Do you want to send emails from your Django app? There are many reasons to send emails from your Django app including email confirmation, password reset, notifications, newsletters, promotions, marketing purposes d There are many ways to send emails from the Django app.
In this article, I am going to explain how to send emails via custom Email ([email protected]) with AWS Simple Email Service (SES) SMTP Server. However, you can use any email [email protected], [email protected] which was the active mail address.
AWS SES has a great response to an SMTP server. You can use AWS SES for small or large complex applications and with the best service, it costs cheap. We all know about the AWS services that that is the best
So how much cost of AWS Simple Email Service (SES)
AWS offers free usage with the first 62,000 emails for each month. After free usage, it’s cost $0.10 for 1000 emails. wow, it’s to cheap cost. if you are sending attachment it’s cost $0.12 for each GB of attachments you send. For more information check this aws ses pricing
Setup AWS SES with Django application
Here is two part of the setup…
- Setup in AWS Management Console
- Setup in Django application
Step #1. First of all let’s setup SES in AWS management console
-
Login to aws management console or create here aws account
-
Find simple email service or ses in aws console
-
Now you are in the SES service section. New account amazon limit there SES Sending limits with 200 emails for each month. you can increase your sending email limits.
Submit a ticket for increase email limit. it will be increased up to 2 days
-
Verify Your Domain address, and you will get an email from Amazon Web Services – Email Address Verification Request, in this email you have a verification link.
click this verification link, it will take you confirmation page of Amazon Web Service.
-
Create credentials for SES. So we use pure SMPT Credentials for SES
- Go to SMPT settings and create credentials
- Choose a IAM UserName
- Now download credentials file. So CSV File will be downloaded
- Open Download file
IAM User Name: ses-smtp-your-username Smtp Username: "your username" example: AKIA6IVWV2ZU4OZYIXOC Smtp Password: "your Password" example: BOWvJ+zG+VMBIyDqT8alFmEqKg6uJpPz6PPMKFsxBoWI
- Go to SMPT settings and create credentials
- Great our AWS setup is now complete we can go to Django setup
Step #2. setup in Django application
-
First, add email config into settings.py file
EMAIL_USE_TLS = True EMAIL_HOST = 'email-smtp.ap-south-1.amazonaws.com' EMAIL_HOST_USER = 'Smpt Username' EMAIL_HOST_PASSWORD = 'Smpt Password' EMAIL_PORT = 587
Note: EMAIL_HOST may be different from your case. find from here:
Now test you setup
from django.core.mail import send_mail >>> send_mail( ... "mail subject", ... "mail message here", ... "[email protected]", ... ["[email protected]", "[email protected]"], ... fail_silently=False, ... html_message=html__ ...)
Response: send_mail return 1 if mail successfully sends other case show errors message because of fail_silently=false.
Note: [email protected], [email protected], [email protected] is dummy mail address it’s not work