AWS Messaging & Targeting Blog
Getting Started with HAQM SES and .NET
This post will help get you started using HAQM SES from .NET applications. Before you start working, make sure you are signed up for HAQM SES as described in the Getting Started Guide. This post assumes you are using Visual Studio for development.
Using SMTP
The easiest way to send email through HAQM SES is via SMTP. The HAQM SES SMTP endpoint requires delivery over authenticated encrypted connections (Transport Layer Security, or TLS).
- Generate your SMTP credentials according to these instructions. Please note that your SMTP credentials are different from your AWS credentials.
- Create a Console Application in Visual Studio.
- Add the following code to the
Main
method:String username = "SMTP-USERNAME"; // Replace with your SMTP username. String password = "SMTP-PASSWORD"; // Replace with your SMTP password. String host = "email-smtp.us-east-1.amazonaws.com"; int port = 25; using (var client = new System.Net.Mail.SmtpClient(host, port)) { client.Credentials = new System.Net.NetworkCredential(username, password); client.EnableSsl = true; client.Send ( "FROM@EXAMPLE.COM", // Replace with the sender address. "TO@EXAMPLE.COM", // Replace with the recipient address. "Testing HAQM SES through SMTP", "This email was delivered through HAQM SES via the SMTP end point." ); }
- Run the application and check the recipient mailbox for your email.
- Advanced users can configure the SMTP credentials and SMTP end point using the <mailSettings> element as described in this HAQM SES forum post.
Using the AWS SDK
The AWS SDK gives you more control over email delivery through HAQM SES. Messages are delivered over HTTPS to the HAQM SES API.
- Create a Console Application in Visual Studio.
- Install the AWS SDK for .NET.
-
SendEmail
is the simplest action provided by the HAQM SES SDK. To send an email using this action, add the following code to yourMain
method:String source = "FROM@EXAMPLE.COM"; // Replace with the sender address. String recipient = "TO@EXAMPLE.COM"; // Replace with the recipient address. String awsAccessKey = "AWS-ACCESS-KEY"; // Replace with your AWS access key. String awsSecretKey = "AWS-SECRET-KEY"; // Replace with your AWS secret key. // Setup the email recipients. var oDestination = new Destination().WithToAddresses(new List<string>() { recipient }); // Create the email subject. var oSubject = new Content().WithData("Testing HAQM SES through the API"); // Create the email body. var oTextBody = new Content().WithData("This email was delivered through the HAQM SES API."); var oBody = new Body().WithText(oTextBody); // Create and transmit the email to the recipients via HAQM SES. var oMessage = new Message().WithSubject(oSubject).WithBody(oBody); var request = new SendEmailRequest().WithSource(source).WithDestination(oDestination).WithMessage(oMessage); using (var client = new HAQMSimpleEmailServiceClient(awsAccessKey, awsSecretKey)) { client.SendEmail(request); }
- Run the application and check the recipient mailbox for your email.
Final Thoughts
We hope that you now have the basic information on how to get started with HAQM SES using .NET. Please review our API reference; it describes all actions, error codes and restrictions that apply to HAQM SES.
If you have comments or feedback about this service, please post them on the HAQM SES forums. We actively monitor the forum and frequently engage with customers. Happy sending with HAQM SES!