Send Email Programmatically


Is there any method / function to sent email programmatically?

1 Like

Yes, check email rules and email alerts. That should do what you need?

1 Like

@charlie-cook thanks for your reply but Email Alert or Email Rules won’t work in my case, i need python function to send email for sending email to the address which are not pre-defined.

Anybody please?

You can use frappe.sendmail() method, it is used vast over frappe app just check with it

1 Like


@hereabdulla @magic-overflow many thanks of both of you,

for viewers :
here is method of sending emails,

def send_email(email_address):
		subject="Subject of the email",
		message= "Content of the email"

Hey @shahid
How can we add particular date to send ,from python code

Sorry i didn’t get you, can you please elaborate?

If your Email account is successfully linked you can use this method

def send_notifications(self):
from import make
msg="Your msg here"

    make(subject = "Email Subject", content=msg, recipients='',
        send_email=True, sender="senderEmail lined in the email account")
    msg = """Email send successfully to Employee"""
    frappe.msgprint("could not send")
1 Like

You can use the scheduler to send the email notification on any specific date and time.

inside hooks file put the scheduler entry for your email function.

Here’re some options for scheduler, means how frequently you can send the email:



Frappe framework has following function to compare the dates and times and use these function to compare the date

scheduler_events = {
    "daily": [
    "daily_long": [
    "cron": {
        "15 18 * * *": [
        "*/6 * * * *": [
        "annual": [


Thanks for your response,

I would like to send email to suppliers one day before request date in purchase order.

and One more condition
If requested date is on monday, then mail should not be sent on sunday instead it should be sent on saturday

The ‘cron’ expression can specify what days of the week to run, so then 0-6 would omit Sunday Linux Crontab Command Help and Examples

So in your case Sunday and Monday notices would both be scheduled to send out Saturday.

1 Like

Hi Omar,

By looking at the code, make() will create new doc of communication.
But I can’t figure out if it also automatically send email?
Will it put sending email also in enqueue?

Which part of make() that send email, is it this ?

if cint(send_email):
    frappe.flags.print_letterhead = cint(print_letterhead)
    comm.send(print_html, print_format, attachments, send_me_a_copy=send_me_a_copy)

I also can’t find any documentation about frappe.sendmail.
Can anyone suggest?

FYI, my scenario is to send notification email after (guest) user fill in a webform.
Thanks in advance for your or anyone comment.

yes this is the part of sending emails

by the way, I am using now frappe.sendmail function for emails issue

So… to have a record of email sent:

  • using frappe.sendmail
  • and create comm doc


Did you figured it out?

I also use frappe.sendmail. Simpler to figure out.

Hello @rahy

Please where did you write these codes on ERPNext?

I wrote it in the coressponding py file in the doctype directory.
You may also able to use the Script Editor.