AWS SES

Brief:

Amazon Simple Email Service (Amazon SES) is a cost-effective email service built on the reliable and scale able infrastructure that Amazon.com developed to serve its own customer base. With Amazon SES, you can send transnational email, marketing messages, or any other type of high-quality content to your customers. You can also use Amazon SES to receive messages and deliver them to an Amazon S3 bucket, call your custom code via an AWS Lambda function, or publish notifications to Amazon SNS. With Amazon SES, you have no required minimum commitments – you pay as you go, and you only pay for what you use.

Need:

In order to send emails, we usually use Gmail. What if I want to send email through code in my application on certain triggers like, application gave error or logs an error in the error log or send verification email to verify the email id or send password reset link. We can use SMTP service which allows sending email through code. Gmail also provides same service but there are limitations in sending emails. You cannot send more than 500 emails per day. Another option is to go with paid services like MailJet, ConstantContact, MailChimp, etc. These are a little costly email solution. If you already have your server on AWS cloud, then you can go with AWS SES service. There is fix limit set to send emails but you can raise a ticket to extend the limit. The charges are very less than other service providers. The charges are little higher if your code is not on AWS cloud.

How It Works:


1. Sign In into your account.
2. Go to http://aws.amazon.com/ses
3. Click on Sign in to console
4. In Application services section click on SES
5. Go to Email Addresses
6. Click on Verify a New Email Address. This is required to confirm your From email address through which all emails will be sent. For example, alerts@domain.com. More info. here http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html
7. Once you have received an email you can then request production access. This will allow you to send emails to unverified email addresses. The number of emails you can send per day will be raised.
8. Below is the script to send email in C#

const String FROM = "SENDER@EXAMPLE.COM"; // Replace with your    "From" address. This address must be verified.
const String TO = "RECIPIENT@EXAMPLE.COM"; // Replace with a "To" address. If your account is still in the sandbox, this address must be verified.

const String SUBJECT = "Amazon SES test (SMTP interface accessed using C#)";
const String BODY = "This email was sent through the Amazon SES SMTP interface by using C#.";

// Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.

const String SMTP_USERNAME = "YOUR_SMTP_USERNAME"; // Replace with your SMTP username. 
const String SMTP_PASSWORD = "YOUR_SMTP_PASSWORD"; // Replace with your SMTP password.

// Amazon SES SMTP host name. This example uses the US West (Oregon) region.
const String HOST = "email-smtp.us-west-2.amazonaws.com";

// The port you will connect to on the Amazon SES SMTP endpoint. We are choosing port 587 because we will use STARTTLS to encrypt the connection.
const int PORT = 587;

// Create an SMTP client with the specified host name and port.

using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(HOST, PORT))
{
// Create a network credential with your SMTP user name and password.
client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);

// Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then
// the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.

client.EnableSsl = true;

// Send the email. 

try
{
     Console.WriteLine("Attempting to send an email through the Amazon SES SMTP interface...");
     client.Send(FROM, TO, SUBJECT, BODY);
     Console.WriteLine("Email sent!");
}
catch (Exception ex)
{
     Console.WriteLine("The email was not sent.");
     Console.WriteLine("Error message: " + ex.Message);
}
}

Console.Write("Press any key to continue...");
Console.ReadKey();

Boston Byte Grabs a Spot in Clutch’s List of Top Software Developers in Massachusetts

Boston Byte is a collective of highly-skilled and highly-professional developers dedicated to solving your technological ...