Menu
Amazon Simple Email Service
Developer Guide (API Version 2010-12-01)

Send an Email Through Amazon SES Using the AWS SDK for .NET

The following procedure shows you how to use Microsoft Visual Studio and AWS Toolkit for Visual Studio to create an AWS SDK project and modify the C# code to send an email through Amazon SES. The process to create a new project based on a project template is similar across Microsoft Visual Studio editions, but we'll go through the procedure using Microsoft Visual Studio Professional 2012.

Before you begin this procedure, complete the setup tasks described in Before You Begin with Amazon SES and Send an Email Through Amazon SES Using an AWS SDK.

Important

In this getting started tutorial, you send an email to yourself so that you can check to see if you received it. For further experimentation or load testing, use the Amazon SES mailbox simulator. Emails that you send to the mailbox simulator do not count toward your sending quota or your bounce and complaint rates. For more information, see Testing Amazon SES Email Sending.

To send an email using the AWS SDK for .NET v.2

  1. Create an AWS project in Visual Studio by performing the following steps:

    1. Open Visual Studio.

    2. Choose File, choose New, and then choose Project.

    3. In the New Project dialog box, in the left pane, expand Installed, expand Templates, and then expand Visual C#.

    4. Under Visual C#, choose AWS.

    5. Choose AWS Empty Project.

    6. In the Name field, type AmazonSESSample. The dialog box should look similar to the following figure.

    7. Choose OK.

  2. In the AWS Access Credentials dialog box, select an existing account or enter the following information:

    • Display Name—Type a name that identifies your account. Next time you create an AWS project in Visual Studio, you will be able to select this account so you do not have to enter the information again.

    • Access Key ID—Enter the AWS access key ID that you obtained in Getting Your AWS Access Keys.

    • Secret Access Key—Enter the AWS secret access key that you obtained in Getting Your AWS Access Keys.

    • Account Number—(Optional) Enter your AWS account number. To find your AWS account number, go to the Security Credentials page in the AWS Management Console and choose Account Identifiers. (If you are not logged into your AWS account, this link will take you to an AWS account sign-in page first.) At the bottom of the page, under Account Identifiers, you will see your AWS Account ID.

    • Default Region—Select the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox status, sending limits, and Amazon SES identity-related settings are specific to a given AWS region, so be sure to select an AWS region in which you set up Amazon SES. For a list of AWS regions that Amazon SES supports, see Regions and Amazon SES.

  3. Choose OK.

  4. In your Visual Studio project, replace the entire contents of Program.cs with the following code:

    Copy
    using System; using System.Collections.Generic; using Amazon.SimpleEmail; using Amazon.SimpleEmail.Model; namespace AmazonSESSample { class Program { public static void Main(string[] args) { 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 (AWS SDK for .NET)"; const String BODY = "This email was sent through Amazon SES by using the AWS SDK for .NET."; // Construct an object to contain the recipient address. Destination destination = new Destination(); destination.ToAddresses = (new List<string>() { TO }); // Create the subject and body of the message. Content subject = new Content(SUBJECT); Content textBody = new Content(BODY); Body body = new Body(textBody); // Create a message with the specified subject and body. Message message = new Message(subject, body); // Assemble the email. SendEmailRequest request = new SendEmailRequest(FROM, destination, message); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox // status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US West (Oregon) region. Examples of other regions that Amazon SES supports are USEast1 // and EUWest1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Amazon.RegionEndpoint REGION = Amazon.RegionEndpoint.USWest2; // Instantiate an Amazon SES client, which will make the service call. AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(REGION); // Send the email. try { Console.WriteLine("Attempting to send an email through Amazon SES by using the AWS SDK for .NET..."); client.SendEmail(request); 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(); } } }
  5. In Program.cs, replace the following with your own values:

    Important

    The email addresses are case-sensitive. Make sure that the addresses are exactly the same as the ones you verified.

    • SENDER@EXAMPLE.COM—Replace with your "From" email address. You must verify this address before you run this program. For more information, see Verifying Email Addresses and Domains in Amazon SES.

    • RECIPIENT@EXAMPLE.COM—Replace with your "To" email address. If your account is still in the sandbox, you must verify this address before you use it. For more information, see Moving Out of the Amazon SES Sandbox.

    • REGION—Set this to the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox status, sending limits, and Amazon SES identity-related settings are specific to a given AWS region, so be sure to select an AWS region in which you set up Amazon SES. In this example, we are using the US West (Oregon) region. Examples of other regions that Amazon SES supports are USEast1 and EUWest1. For a complete list of AWS regions that Amazon SES supports, see Regions and Amazon SES.

  6. Save Program.cs.

  7. To build the project, choose Build and then choose Build Solution.

  8. To run the program, choose Debug and then choose Start Debugging.

  9. Review the program's console output to verify that the sending was successful. (You should see "Email sent!")

  10. Log into the email client of the recipient address. You will find the message that you sent.