Tech Incent
django

Django Send Email with AWS Simple Email Service(SES)

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…

  1. Setup in AWS Management Console
  2. Setup in Django application

Step #1. First of all let’s setup SES in AWS management console

  1. Login to aws management console or create here aws account
  2. Find simple email service or ses in aws console

    aws ses search

  3. 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.

    increae

    Submit a ticket for increase email limit. it will be increased up to 2 days
    increase
  4. 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.
    verify-d

  5. Create credentials for SES. So we use pure SMPT Credentials for SES

    1. Go to SMPT settings and create credentials
      add-user
    2. Choose a IAM UserName
      add-user-2
    3. Now download credentials file. So CSV File will be downloaded
      add-user-3
    4. Open Download file
      IAM User Name: ses-smtp-your-username
      Smtp Username: "your username" example: AKIA6IVWV2ZU4OZYIXOC
      Smtp Password: "your Password" example: BOWvJ+zG+VMBIyDqT8alFmEqKg6uJpPz6PPMKFsxBoWI
      
  6. Great our AWS setup is now complete we can go to Django setup

Step #2. setup in Django application

  1. 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:
    BOWvJ+zG+VMBIyDqT8alFmEqKg6uJpPz6PPMKFsxBoWI

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

Related posts

How to deploy django and react in heroku ?

Tech Incent

How to set up django react together ?

Sajal Mia

Django abstractuser with example

Sajal Mia

Leave a Comment