Email Notification in Django

Published On: 29 December 2020.By .
  • General

For sending email notification in django we use django’s send_mail function, with using some smtp sever.

we can get smtp server from free smtp service providers like SendGrid.

In our settings.py file we define some parameters for sending mails like:-

we define a function in our service file for sending mails like-

Now if we want to send mails asynchronously we define a decorator:

and define a async send_mail function which calls previously defined send_mail function,

Now for sending template based email notifications we define some types of notifications in a constant file like:

and then a general function for sending those mails:

and we are using edited templates(html templates) for rendering and we pass all related data in context_data which is a dict object.

Next for sending these asynchronously we define a new async function in which we call our send_email_notification function.

Now we can call it like-

 

Related content

That’s all for this blog