mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 18:04:46 +00:00
📝 Add docstrings to fix/email-campaign-timeout
Docstrings generation was requested by @pratikb64. * https://github.com/frappe/erpnext/pull/51994#issuecomment-3783742931 The following files were modified: * `erpnext/crm/doctype/email_campaign/email_campaign.py`
This commit is contained in:
committed by
GitHub
parent
a030ea6fde
commit
f6c8d5e038
@@ -100,6 +100,16 @@ def send_email_to_leads_or_contacts():
|
|||||||
|
|
||||||
|
|
||||||
def send_mail(entry, email_campaign):
|
def send_mail(entry, email_campaign):
|
||||||
|
"""
|
||||||
|
Send the rendered email template to the recipients defined by the campaign, creating one communication per batch.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
entry (dict): Campaign schedule entry containing at least the `email_template` reference and `send_after_days`.
|
||||||
|
email_campaign (Document): Email Campaign document that provides recipient selection, sender, campaign name, start/end dates and related context.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
comm (Document or None): The last created communication Document for the final recipient batch, or `None` if no recipients were found.
|
||||||
|
"""
|
||||||
recipient_list = []
|
recipient_list = []
|
||||||
if email_campaign.email_campaign_for == "Email Group":
|
if email_campaign.email_campaign_for == "Email Group":
|
||||||
for member in frappe.db.get_list(
|
for member in frappe.db.get_list(
|
||||||
@@ -116,19 +126,29 @@ def send_mail(entry, email_campaign):
|
|||||||
email_template = frappe.get_doc("Email Template", entry.get("email_template"))
|
email_template = frappe.get_doc("Email Template", entry.get("email_template"))
|
||||||
sender = frappe.db.get_value("User", email_campaign.get("sender"), "email")
|
sender = frappe.db.get_value("User", email_campaign.get("sender"), "email")
|
||||||
context = {"doc": frappe.get_doc(email_campaign.email_campaign_for, email_campaign.recipient)}
|
context = {"doc": frappe.get_doc(email_campaign.email_campaign_for, email_campaign.recipient)}
|
||||||
# send mail and link communication to document
|
subject = frappe.render_template(email_template.get("subject"), context)
|
||||||
comm = make(
|
content = frappe.render_template(email_template.response_, context)
|
||||||
doctype="Email Campaign",
|
|
||||||
name=email_campaign.name,
|
# Batch recipients to avoid timeout when processing large email groups
|
||||||
subject=frappe.render_template(email_template.get("subject"), context),
|
BATCH_SIZE = 100
|
||||||
content=frappe.render_template(email_template.response_, context),
|
comm = None
|
||||||
sender=sender,
|
|
||||||
bcc=recipient_list,
|
for i in range(0, len(recipient_list), BATCH_SIZE):
|
||||||
communication_medium="Email",
|
batch = recipient_list[i : i + BATCH_SIZE]
|
||||||
sent_or_received="Sent",
|
|
||||||
send_email=True,
|
comm = make(
|
||||||
email_template=email_template.name,
|
doctype="Email Campaign",
|
||||||
)
|
name=email_campaign.name,
|
||||||
|
subject=subject,
|
||||||
|
content=content,
|
||||||
|
sender=sender,
|
||||||
|
bcc=batch,
|
||||||
|
communication_medium="Email",
|
||||||
|
sent_or_received="Sent",
|
||||||
|
send_email=True,
|
||||||
|
email_template=email_template.name,
|
||||||
|
)
|
||||||
|
|
||||||
return comm
|
return comm
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user