I'm trying to send email via Amazon SES new SMTP service using .NET's built-in SmtpClient
Code:
var emailClient = new SmtpClient("email-smtp.us-east-1.amazonaws.com", 465);
emailClient.EnableSsl = true;
....
emailClient.Send(message);
I get an exception:
Unable to read data from the transport connection: net_io_connectionclosed
Google says this error means that I can't reach SMTP server. They require TLS which I beleive achieved by "EnableSsl" property.
Anybody know how I need to tweak my code to make it work?
EDIT:
I guess I will close this question. No, it's not possible to do what I want with SmtpClient
https://forums.aws.amazon.com/thread.jspa?messageID=302112񉰠
It is possible to do this by specifying port 587.
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network enableSsl="true" port="587" host="email-smtp.us-east-1.amazonaws.com" password="[password]" userName="[username]"/>
</smtp>
</mailSettings>
</system.net>
With that as the configuration, you can use the SmtpClient as you normally would
var client = new SmtpClient();
var message = new MailMessage(fromemail, recipient, subject, body);
client.Send(message);
I can confirm that it works with STARTTLS and port 587.
Hope that helps
According to Amazon - it is not supported as we used to.
https://forums.aws.amazon.com/thread.jspa?messageID=302112񉰠
The .NET email TLS libraries only support STARTTLS which SES does not support today. We support what is called "TLS Wrapper" or SMTPS authentication. I can understand how this would be frustrating, but you can use OpenSSL as a workaround and tunnel through that software running on your computer to use .NET to program against our SMTP endpoint.
As masterfu mentions in his blog post, Amazon SES started supporting STARTTLS in March of 2012.
Below is the code that I used to get SMTP working with Amazon.
string username = ConfigurationManager.AppSettings["AWSSMTPUser"];
string password = ConfigurationManager.AppSettings["AWSSMTPPass"];
SmtpClient smtp = new SmtpClient();
smtp.Host = "email-smtp.us-east-1.amazonaws.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(username, password);
smtp.EnableSsl = true;
smtp.Send(mail);
Now SES supports STARTTTLS:
Outgoing server (SMTP)—25, 587, or 2587 (to connect using STARTTLS), or 465 or 2465 (to connect using TLS Wrapper).
Pruf link: http://s3.amazonaws.com/awsdocs/ses/latest/ses-dg.pdf
For Anyone who wants to send with normal .Net SMTPClient. It is possible as you just need a wrapper.
Here's a link with all the info:
http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/SMTP.Client.html
Install the tunneling software and configure as the describe in the link then its as simple as :
System.Net.Mail.SmtpClient sc = new SmtpClient();
sc.Host = host;
sc.Port = port;
sc.Credentials = new NetworkCredential(username, password);
sc.Send(mm);
Try using port no. 2587, other port 25, 425, 587 dint work for my case.
你在web.config中设置了defaultCredentials =“false”吗?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.