Hi, I have a custom Doctype called Linked Third Party. It is basically a form with contact details, now I want to send an email based off of an Email Template (With Attachments) to an email within that form each time I save it. Let’s say my form has the email abc@abc.com, I want to send an email to this email when I save the form. I have been studying the user.py file and the hooks.py file to no avail.
Hi @Vesper_Solutions,
regarding issue #1, you could make use of a Notification - I am not aware, if you can make use of E-Mail Templates within Notifications. But for sure, you can just add your custom HTML within that notification: Notification
In notification you have to select your doctype as you mentioned ’ Linked Third Party’ and then select event after save.
In below one child table is there where you can select your email field where you want to send email.
If that field not available in selection then go to your doctype and select opetion as ‘Email’ for your email field so you will get that field in recipient child table of notification.
I can do that yes but that is not what I want to do. The email I wish to send (automatically) is not to a user of the app (a system user) but an external email. In the doctype Linked Third Party is a field called email (not for a system user). I wish to send an email to the address from the email field.
Thanks but notifications are for system users. The email address I want to send the mail to is not of system users but rather external emails saved within a doctype
I aim to use the frappe.sendmail functionality, I read through this thread: Attachments with frappe.sendmail
to no avail. I did come up with this code, which does not work unfortunately. Basically I have a doctype called Secondary Sources. There is an email address in that form and I wish to send an email to that address each time a new Secondary Source document is created and saved. Here’s my code :
def send_email_to_party(self):
content = frappe.render_template('yourappname/templates/emails/email_template.html', {
'recipient_name': self.recipient_name,
'email': self.email
#put here the variables in the template
})
frappe.sendmail(
recipients = self.email, #this is the email to your recipient as you want
sender = "your_sender_email",
subject = "The subject of your email",
content = content,
now = True
)
Here are more parameters in frappe.sendmail(). Actually there are more but I don’t use them and can’t remember them
recipients
cc
bcc
sender
subject
content
reply_to
reference_doctype
reference_name
header
now
But I can’t make it work.
So I prefer using the sendmail. And if necessary, do frappe.new_doc('Communication') to make a new Communication doctype when sending email.
Although I am a bit curios. Is there any way to put the sendmail function through a loop. Let’s say there is a child table with email fields, can I somehow send emails to all emails from the rows of the child table?
Honestly I don’t know.
But maybe you can put sendmail inside the loop instead of only looping the email inside sendmail.
One concern though, because sending email takes time, perhaps better to put sendmail in enqueue and have the background job send them.
Or if I’m not mistaken, using make (Communication) does put the email in que jobs.
Well, I’m not programmer so I might be wrong. And I intend to learn also if somebody has the answer.