SMTP message with SSL not working with GoDaddy email address in ASP.NET

When I try to send STMP email to ASP.NET using SSL to my new GoDaddy email address, this will not work. I get an error message Unable to read data from the transport connection: net_io_connectionclosed.

Here are the email settings for the server:

enter image description here

Here is a snippet from my web.config with 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 is 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 while it just quits.

How can I send these emails using SSL?

+5
source share
2 answers

This is discussed in more detail in this older question , including a 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 the options discussed there is to use a well-preserved library that has implicit SSL support. MailKit would be a good way to do this.

Alternatively, consider using a third-party email relay service such as SendGrid, Mandrill, Mailgun, and others. This will greatly improve your chances that users will actually receive your mail in the inbox, and not in the spam and junk mail folders.

+3
source

From your screenshot, I assume that your site is hosted outside of godaddy , so you can use "smtpout.secureserver.net".

If your site is hosted by godaddy, you need to change the configuration 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 changing the port From 465 to 587

For Implicit SSL, we used netimplicitssl :

here is a 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 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()); } 
+1
source

Source: https://habr.com/ru/post/1266386/


All Articles