When I try to send STMP email in ASP.NET using SSL on my new GoDaddy email address, it does not work. I receive an error message saying Unable to read data from the transport connection: net_io_connectionclosed.
Here are the email settings for the server:
Here's the snippet from my web.config with the email server information:
<system.net> <mailSettings> <smtp from="no-reply@mysite.com" > <network host="smtpout.secureserver.net" port="465" userName="no-reply@mysite.com" password="password123" enableSsl="true" /> </smtp> </mailSettings> </system.net> And here's the C# code that sends the email.
MailMessage message = new MailMessage(); message.To.Add(new MailAddress(to)); message.Subject = "Message from " + inputModel.Name; message.Body = body; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { smtp.Send(message); } Ports 80, 3535, and 25 work fine without SSL, but none of the four work with SSL. I even tried port 587 with SSL, and after quite a long time it just times out.
How can I get these emails to send using SSL?
2 Answers
Answers 1
Much about this in this older question, including the description of the problem - that SmtpClient only supports "explicit SSL", and you need to do "implicit SSL" to just talk SSL on port 465 directly.
A better and more modern approach than those options discussed there, is to use a well maintained library that has implicit SSL support. MailKit would be a good way to go for this.
Alternatively, consider using a third-party email relay service, such as SendGrid, Mandrill, Mailgun, and others. Doing so will greatly improve your odds of users to actually receive your mail in their inbox rather than a spam/junk folder.
Answers 2
From your Screenshot i'm assuming your site is hosted outside the godaddy so then you can use "smtpout.secureserver.net" .
if your site hosted on godaddy then you need to change config as follows:
<system.net> <mailSettings> <smtp from="no-reply@mysite.com"> <network host="relay-hosting.secureserver.net"/> </smtp> </mailSettings> </system.net> If you want to use Explicit ssl Try to change the Port From 465 to 587
For Implicit SSL we used netimplicitssl :
here is the sample taken from this answer
var mailMessage = new MimeMailMessage(); mailMessage.Subject = "test mail"; mailMessage.Body = "hi dude!"; mailMessage.Sender = new MimeMailAddress("you@gmail.com", "your name"); mailMessage.IsBodyHtml = true; mailMessage.To.Add(new MimeMailAddress("yourfriend@gmail.com", "your friendd's name")); mailMessage.Attachments.Add(new MimeAttachment("your file address")); var emailer = new SmtpSocketClient(); emailer.Host = "your mail server address"; emailer.Port = 465; emailer.EnableSsl = true; emailer.User = "mail sever user name"; emailer.Password = "mail sever password" ; emailer.AuthenticationMode = AuthenticationType.PlainText; emailer.MailMessage = mailMessage; emailer.OnMailSent += new SendCompletedEventHandler(OnMailSent); //Send email emailer.SendMessageAsync(); // A simple call back function: private void OnMailSent(object sender, AsyncCompletedEventArgs asynccompletedeventargs) { Console.Out.WriteLine(asynccompletedeventargs.UserState.ToString()); } 
0 comments:
Post a Comment