Thursday, 7 March 2019

Configure Simple Email Service in Python with Postman and Postfix

Amazon Simple Email Service is a cloud-based email sending service designed to help to the customer to send marketing, notification, and transactional emails.

Amazon Simple Email Service is a scalable and cost-effective email sending service customized for both bulk and transactional for both businesses and developers. Amazon SES contains features like content filtering technologies, dedicated IP addresses, and a reputation dashboard. Retaining a good position makes sure that your messages deliver to your customer's inboxes.

As Simple Email Service is cost effective means pay only for what you use. There are no upfront fees, as well as no time-consuming pricing negotiations, no fixed expenses, and no minimum charges. And, if you send from an application hosted in Amazon EC2, then AWS provides you first 62,000 emails free for every month.

Use configuration sets to generate rules which are applied to the emails you send using Amazon SES. Send email metrics to Amazon CloudWatch for further analysis, otherwise receive notifications through Amazon SNS.

You can use AWS SMTP interface or one of the AWS SDKs to integrate Amazon SES directly into your existing applications. Besides, you can integrate the email sending potentials of Amazon SES into the software you use earlier, like ticketing systems and email clients.

In this service application programming interface (API) calls to Amazon SES through boto, a Python library for AWS. Also a sample command-line tool called Postman, which is designed for use in your Postfix configuration to send mail through Amazon SES.

For getting this service, you have to install postman with the command line. If you do not have pip installed, you can install it manually by downloading the postman from the URL - http://pypi.python.org/pypi/postman . After installation of postman install boto as the library is a dependency.

After installation you must have to configure boto to use your account with access credentials (aws_access_key_id and aws_secret_access_key) by editing /etc/boto.cfg file. In standard boto fashion, you get a connection object for the service. Next, call the send_raw_email method on the connection object with content from standard input. That's all there is to sending an email message using Python and boto through Amazon SES.

After installation and configuration you have to verify the email address,this is a simple call to a single boto connection method, verify_email_address. You need to call this method for every email address from which you want to send a message. In fact, while in the Sandbox, you will also need to call this method for the email addresses you are going to send mail to. After calling this method, Amazon SES sends an email with a confirmation link. The recipient must click the link before the address is considered verified. Once verified, you can send mail as that address. To check which email addresses are verified on your account, you can run the list_verified command on your command prompt. To check current limit and and already sent information use show_quota and show_stats commands. These are simple wrappers around two boto methods.get_send_quota and get_send_statistics.that provide some parsing out of the data structure that botoreturns to provide cleaner console output.

Also command delete_verified provides a way to remove an email address from the verified emails that are allowed be in the From header of an email message. The rest of the __main__.py module consists of Python code that parses input arguments and calls the right command function. The module is missing one API call that boto does provide, however a more structured email send that does not require a raw email message body. Adding this call provides a clean method for sending email messages from the command line without having to structure and PIPE in content with email headers.

There are two limits on your Amazon SES account i.e a daily quota and a send rate. The daily limit is how many emails you are allowed to send within a 24-hour period. The send rate is how many emails your account can send per second. For example, you start out with a daily quota of 1000 and a 1/email/sec rate, so if you had a batch of 1000 emails to send, you would have to throttle the sending to 1 per second, or else you would get an exception. So, it would take approximately 17 minutes to send all 1000 messages, but after doing so, you would need to wait another 23.75 hours until you could send anymore. The postman show_quota command will help you in observing these limits, which Amazon increases depending on your usage over time.

Amazon provides an API to fetch statistics on emails sent grouped in 15-minute intervals for a rolling previous two-week period. These statistics are useful for assisting in monitoring how your application is using and sending email. They provide counts on delivery attempts, complaints, bounces, and rejects. The postman show_stats command prints these figures to the console.

To avoid spam filtering or outright rejections from ISPs, it's an good idea to set Sender Policy Framework and Sender ID records. These are Domain Name System (DNS) TXT records that have the following content:

SPF : v=spf1 include:amazonses.com ?all
Sender ID : spf2.0/pra include:amazonses.com ?all

These DNS records entries must have to add in DNS zone file to ensure high-quality delivery of your email.

No comments:

Post a Comment

Robot Operating System (ROS) Melodic Supported By AWS RoboMaker

AWS RoboMaker is a service that is easy to develop, test, and deploy intelligent robotics applications at scale. RoboMaker increase the v...