Hey guys, I want to implement a function which i can send a mail to a lead by choosing out of the email template. All the things i want are working but it seems to fail at the last instance.
this is the error i get when i want to send it: Lead [“CRM-LEAD-2024-00025”] not found
it says that the Lead with that ID isnt found, but this lead exists, and the URL of the Lead is also correct. I think the mistake is by handing over the lead_id but Im not completely sure.
This is my javascript and python code.
lead_list.js
function send_email_to_leads(lead_id, template) {
frappe.call({
method: "erpnext.crm.doctype.lead.send_email_to_leads.send_email_to_leads",
args: {
lead_id: lead_id,
template: template
},
callback: function(response) {
if (response.message) {
frappe.show_alert(__("E-Mail erfolgreich gesendet"));
} else {
frappe.show_alert(__("Fehler beim Senden der E-Mail"));
}
}
});
}
send_email_to_leads.py
import frappe
@frappe.whitelist()
def send_email_to_leads(lead_id, template):
lead = frappe.get_doc("Lead", lead_id)
email_template = frappe.get_doc("Email Template", template)
email_content = frappe.render_template(email_template.message, {"doc": lead})
frappe.sendmail(
recipients=lead.email_id,
sender=frappe.session.user,
subject=email_template.subject,
content=email_content
)
return True