I am using amazon SES SMTP for sending mail, But I am getting error "Unable to read data from the transport connection: net_io_connectionclosed
Here is my code:
const String FROM = "firstname.lastname@example.org"; // Replace with your "From" address. This address must be verified.
const String TO = "anwesha@dynamiclevels.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 = "USERNAME"; // Replace with your SMTP username.
const String SMTP_PASSWORD = "PASSWORD"; // Replace with your SMTP password.
// Amazon SES SMTP host name. This example uses the US West (Oregon) region.
const String HOST_SES = "email-smtp.us-east-1.amazonaws.com";
// Port we 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 = 465;
// Create an SMTP client with the specified host name and port.
SmtpClient client = new System.Net.Mail.SmtpClient(HOST_SES, 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.
Console.WriteLine("Attempting to send an email through the Amazon SES SMTP interface...");
client.Send(FROM, TO, SUBJECT, BODY);
catch (Exception ex)
Console.WriteLine("The email was not sent.");
Console.WriteLine("Error message: " + ex.Message);
Console.Write("Press any key to continue...");