Setup Amazon AWS Emails Scripts for PHP, Python, Rails, C# & .Net

Facebooktwittergoogle_plusredditpinterestlinkedinmail

A tutorial on how to Setup Amazon AWS / SES Emails Scripts for PHP, Python, Rails, C# & .Net

In this tutorial we are going to cover how to use Amazon SES to send emails through your server on various coding platforms. We have covered PHP, Python, Rails, C# and .Net.

 

 

php_mysql_logo

Amazon SES attachments – Amazon SES send Email Script Snippet PHP

 

It’s simple to install the Amazon SDK utilizing PEAR (per Amazon documentation):

 

 

  1. Install the SDK
  2. Know when a account is sandboxed or not – If you account is sandboxed, you’ll just be capable of sending emails to the e-mail addresses inside the verified senders list.
  3. Be sure the source email’s sending address is indexed because a verified transmitter – Verify an e-mail address you are using which is implemented inside the test code.  Check this e-mail as well as the ReturnPath address inside the AWS system in the event you are getting the “Email address is not verified” mistake.
  4. If you utilize the ReturnPath parameter (not shown here) to obtain bounced emails, then the e-mail address or domain needs to be verified as well

 

If you have the appropriate credentials, sending Email utilizing the SDK is easy.

Same code:

 

 

Result:
Run the above mentioned code utilizing the correct info ensuring emails are varified.  Ensure to set the SenderID, DKIM, plus SPF and domain information in Amazon correctly to avoid a emails getting marked as spam.

Using Attachments:
Use this illustration code inside the system to send an e-mail with an connection utilizing Amazon SES.

 

 

amazon-ses-pricing

Amazon SES Pricing Comparison for Email Marketing Software

 

 

Amazon SES email Marketing Software
Send newsletters 100x cheaper via Amazon Simple email services & Sendy.

Do you want to save $10000 each year on your email marketing budget? Send your email with Amazon SES international scalable high end servers. Send newsletters 100x cheaper via Amazon Simple email services. A self hosted email marketing software.


Download the Email Marketing Software
 

 

 


 

python-logo

 

Amazon SES attachments – Amazon SES send Email Script Snippet Python

 

For sending emails I recommend using Amazon Easy Email Service (Amazon SES). It looks to be a inexpensive along with a reliable method of sending emails.

I have found several Python libraries for Amazon SES, however, almost all of them handle encodings severely… Therefor I am sharing my helper class that utilizes boto.ses plus could correctly send encoded HTML plus text emails.

 

 

 

amazon-ses-pricing

Amazon SES Pricing Comparison for Email Marketing Software

 

Sendy Python Downloads

Amazon SES email Marketing Software
Send newsletters 100x cheaper via Amazon Simple email services & Sendy.

Do you want to save $10000 each year on your email marketing budget? Send your email with Amazon SES international scalable high end servers. Send newsletters 100x cheaper via Amazon Simple email services. A self hosted email marketing software.

Download the Email Marketing Software

 

 


 

rails-logo

 

Amazon SES attachments – Amazon SES send Email Script Snippet Rails

Why employ Amazon SES?

 

Today the main focus on email marketing is cost. At the active e-mail rates in the market, you might conserve over $10,000 inside 2014 utilizing Amazon SES over SendGrid for Airbrake.

 

In the meantime, we’re writing about Amazon SES to find how perfectly it works inside terms of deliverability, blacklisting, etc.

 

Open source library

 

A week following Amazons announced service, there were a great amount of libraries on Github for Amazon SES. I selected drewblas/aws-ses (the aws-ses gem).

 

Comparing SendGrid implementation inside a Rails app

 

How to employ SendGrid inside a Rails app:

 

 

You don’t need a special gem: it’s just SMTP.

 

Using the aws-ses gem in a Rails app

 

Amazon SES requires some HMAC’ing and other stuff, but when using a library, it’s still pretty easy and it has the same dependencies as Rails.

 

Add the gem to your Gemfile:

 

 

Extend ActionMailer in config/initializers/amazon_ses.rb:

 

 

Set the delivery method in config/environments/{staging,production}.rb:

 

Then you are done!

 

amazon-ses-pricing

Amazon SES Pricing Comparison for Email Marketing Software

 

Ruby on Rails Sendy Downloads

 

Amazon SES email Marketing Software
Send newsletters 100x cheaper via Amazon Simple email services & Sendy.

Do you want to save $10000 each year on your email marketing budget? Send your email with Amazon SES international scalable high end servers. Send newsletters 100x cheaper via Amazon Simple email services. A self hosted email marketing software.


Download the Email Marketing Software
 

 

 


 

c-sharp-logo-1

 

Amazon SES attachments – Amazon SES send Email Script Snippet C#

 

Here is the C# application you can use.

 

 

amazon-ses-pricing

Amazon SES Pricing Comparison for Email Marketing Software

 

 

Amazon SES email Marketing Software
Send newsletters 100x cheaper via Amazon Simple email services & Sendy.

Do you want to save $10000 each year on your email marketing budget? Send your email with Amazon SES international scalable high end servers. Send newsletters 100x cheaper via Amazon Simple email services. A self hosted email marketing software.


Download the Email Marketing Software
 

 

 


 

new-net-logo-microsoft

 

Amazon SES attachments – Amazon SES send Email Script Snippet .net

 

 

SendRawEmail doesn’t provide much functionality. In truth, you need to do all functions to build the e-mail by yourself. However, it does imply almost what we want with the e-mail.

There continue to be certain restrictions. Amazon imposes a 50 recipient limit per e-mail, a maximum 10Mb per e-mail, plus you are able to add a minute quantity of file kinds. This really is, I think to lessen the ability for individuals to employ the service also to help avoid spam while helping the legitimate uses for the service.

 

Building an email

You need to figure out the headers, the method and the multi-part MIME is put together the character encoding (considering e-mail is constantly delivered utilizing a 7-bit encoding) and so forth.

 

However, I did discover a piece of code that someone else had written to do the heavy work for me. Essentially, what he’s doing is constructing a mail message using the built in System.Net.Mail.MailMessage type in .NET and then using .NET’s own classes to create the raw mail message as a MemoryStream, which is what Amazon SES wants.

I’ve refactored the code in the linked post so that it is slightly more efficient if you are calling it multiple times. Some of the operations need only be carried out once regardless of the number of times you generate emails, so it removes those bits off to a static initialiser so that they only happen once.

Here’s my refactored version of the code:

 

 

 

At initial glance, the MemoryStream is disposed of does appear a bit counter-intuitive, nevertheless several techniques of MemoryStream  function whenever the stream is closed, like ToArray().

Incidentally, if you would like to find what the raw e-mail looks like you are able to utilize a part of code like this to receive the raw e-mail in a string:

 

 

Using SendRawEmail

Because you’re doing all the work, the code that specificaly interacts with Amazon SES is very simple.

 

 

Thats it you can now send emails with Amazon SES attachments

 

 

amazon-ses-pricing

Amazon SES Pricing Comparison for Email Marketing Software

 

.Net Sendy Downloads

 

Amazon SES email Marketing Software
Send newsletters 100x cheaper via Amazon Simple email services & Sendy.

Do you want to save $10000 each year on your email marketing budget? Send your email with Amazon SES international scalable high end servers. Send newsletters 100x cheaper via Amazon Simple email services. A self hosted email marketing software.


Download the Email Marketing Software
 

Leave a Reply