How To Send And Receive Email With Django And Amazon SES

We always compete in this technological world by providing our best services. One of our most prominent service is Amazon SES for sales and marketing module, where our clients are extremely happy and wants to continue their business partnership with our AWS consulting

Using Amazon SES, You can send and receive email from your verified emails and domains. SES offers email receiving for entire domains or for individual addresses within a domain.We can use other AWS services S3(to store encrypted messages in bucket), SNS topic(to process the message, lamda function).

To send, receive, process the incoming messages, we have a package called django-ses-gateway


pip install django-ses-gateway

Things To Do Before Integration:

1. You must have an AWS account and you need to verify domain in SES to confirm that we are using those domains or to prevent from others using it. Once your domain is verified, then all your emails in the domain will also be verified.

    AWS_ACCESS_KEY_ID = "Your AWS Access Key"

    AWS_SECRET_ACCESS_KEY = "Your AWS Secret Key"

2.To use Amazon SES as your email receiver, you must create at least one active receipt rule set in which you have specified the sns topic(to route messages to an endpoint), s3 bucket(to store messages), lamda function(to process the receiving email) details.

3. After creating the rule set, for an sns topic you need to specify the list of recipients to which you want to process the message.

4. You need to subscribe to the specified SNS topic by providing your domain url(which handles email recieving) as an endpoint. You can give multiple enpoints which may either email, AWS SQS, HTTP or HTTPS.

5. In SES panel, you can also give a list of ip address to which you want reject the email receiving.

How amazon ses performs email receiving:

1. When user replies to an email, then it checks in the active receipt rule set(checks the specified email address,  all addresses in the domain.) in the particular region.

2. If any rule set matches, then it checks against your IP address filters, and rejected if there any matches.

3. then after ses will store those messages in an crypted format using a key stored in AWS Key Management Service (KMS), publish the message to a specified SNS topic(endpoint).


1. Sending an email

    from django_ses_gateway.receiving_mail import sending_mail

    sending_mail(subject, email_template_name, context, from_email, to_email)

    Here we are sending a from_mail as <unique-identifier> Here unique identifier will be used to process the reply to thi mail.

2. Receiving an email

    from django_ses_gateway.receiving_mail import sns_notification

    subject, from_mail, to_mail, hash_code, mail_content = sns_notification(request.body)

    Using the unique identifier(hash_code), we can easily process or store the incoming messages.

It will process your message content, will return the email subject, from mail, to email(, hashcode(abc) or unique-identifier, mail content.

You can view the complete documentation here.

Github Repository:

Posted On 19 January 2017 By MicroPyramid

About Micropyramid

Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.

Need any Help in your Project?Let's Talk


Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
*We don't provide your email contact details to any third parties