Amazon Simple Email Service
Developer Guide

Send an Email Through the Amazon SES SMTP Interface with C#

The following procedure shows how to use Microsoft Visual Studio to create a C# console application that sends an email through Amazon SES. The procedures in this section apply to Visual Studio 2017, but the process of creating C# console applications is similar across Microsoft Visual Studio editions.

Before you perform the following procedure, complete the setup tasks described in Before You Begin with Amazon SES and Send an Email Through Amazon SES Using SMTP.


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 Amazon SES SMTP interface with C#

  1. Create a console project in Visual Studio by performing the following steps:

    1. Open Microsoft Visual Studio.

    2. On the File menu, choose New, Project.

    3. On the New Project window, in the left pane, expand Installed, expand Templates, and then expand Visual C#.

    4. Under Visual C#, choose Windows Classic Desktop.

    5. On the menu at the top of the window, choose .NET Framework 4.5, as shown in the following image.

                                    The .NET Framework selection menu on the New
                                        Project window.


      You can select a later version of the .NET Framework if necessary.

    6. Choose Console App (.NET Framework).

    7. In the Name field, type AmazonSESSample.

    8. Choose OK.

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

    using System; namespace AmazonSESSample { class Program { static void Main(string[] args) { // Replace with your "From" address. This address must be verified. const String FROM = ""; // Replace with a "To" address. If your account is still in the // sandbox, this address must be verified. const String TO = ""; const String SUBJECT = "Amazon SES test (SMTP interface accessed using C#)"; const String BODY = "This email was sent through the Amazon SES SMTP interface " + "using C#."; // Supply your SMTP credentials below. Note that your SMTP // credentials are different from your AWS credentials. // Replace with your SMTP username. const String SMTP_USERNAME = "SMTP_USERNAME"; // Replace with your SMTP password. const String SMTP_PASSWORD = "SMTP_PASSWORD"; // Amazon SES SMTP host name. This example uses the US West // (Oregon) region. const String HOST = ""; // 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 email..."); 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(); } } }
  3. In Program.cs, replace the following email addresses with your own values:


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

  4. In Program.cs, replace the following SMTP credentials with the values that you obtained in Obtaining Your Amazon SES SMTP Credentials:


    Your SMTP credentials are different from your AWS credentials. For more information about credentials, see Using Credentials With Amazon SES.

    • YOUR_SMTP_USERNAME—Replace with your SMTP username. Note that your SMTP username credential is a 20-character string of letters and numbers, not an intelligible name.

    • YOUR_SMTP_PASSWORD—Replace with your SMTP password.

  5. (Optional) If you want to use an Amazon SES SMTP endpoint in a Region other than US West (Oregon), you need to change HOST in Program.cs to the endpoint you want to use. For a list of Amazon SES endpoints, 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. Sign in to the email client of the recipient address. You will find the message that you sent.