When to use API vs SMTP in Django

Can API be used to replace SMTP for mail sending in Django especially for things like reset password and mail confirmation.

I will really love if I can get clarification on a topic in django. I am a newbie to django and when it comes to sending mail I register for Mailgun and used the API since I have used requests before but picking up django to work with I am trying to do user registration using DJ-Rest-auth and django_allauth and there is thing about configuring email backend using SMTP.

my question is

  • Can i do without using SMTP for django_allauth if Yes a workflow how to connect my password reset to use the api for mail.
  • I can easily pass in the mail function to serve as an alert in the views when user registers

You should not write your plain own mail sending function, you should always use Django's builtin send_mail (or related) function(s), and configure a custom email backend in your settings.

If you need to change how emails are sent you can write your own email backend. The EMAIL_BACKEND setting in your settings file is then the Python import path for your backend class.

https://docs.djangoproject.com/en/3.2/topics/email/#defining-a-custom-email-backend

Django can automatically send various emails in various circumstances, so centralising that configuration so all email sending uses your configured mail sending settings is important, unless you have specific reasons against that.

Given that this is such a pluggable architecture, and both Django and Mailgun are popular, there are existing modules that allow you to send email via Mailgun with such a simple configuration change: https://djangopackages.org/grids/g/email/

Back to Top