Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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:

enter image description here

Here's the snippet from my web.config with the email server information:

<system.net>
  <mailSettings>
    <smtp from="[email protected]" >
      <network host="smtpout.secureserver.net" port="465" userName="[email protected]" 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?

like image 353
Jacob Stamm Avatar asked Apr 05 '17 20:04

Jacob Stamm


2 Answers

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.

like image 83
Matt Johnson-Pint Avatar answered Sep 22 '22 10:09

Matt Johnson-Pint


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="[email protected]">
        <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("[email protected]", "your name");
mailMessage.IsBodyHtml = true;
mailMessage.To.Add(new MimeMailAddress("[email protected]", "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());
}
like image 31
Tummala Krishna Kishore Avatar answered Sep 21 '22 10:09

Tummala Krishna Kishore