0
votes

I am new ASP.Net and trying fix an mail issue. My website is hosted on godaddy server and its developed in ASP.Net. Trying to send an mail using following script but its throwing error as "Failure sending mail"

MailMessage mail = new MailMessage("firstmail@mail.com", "sfirstmail@mail.com");
    SmtpClient client = new SmtpClient();
    client.Host = "myhosting.secureserver.net";

    // Tried "relay-hosting.secureserver.net" -Errors-Unable to connect
    // Tried "smtpout.secureserver.net" -Errors-Unable to read data from
    // the transport connection: net_io_connectionclosed

    client.Port = 3535;  //Tried 80, 3535, 25, 465 (SSL)
    client.UseDefaultCredentials = false;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = false;
    client.ServicePoint.MaxIdleTime = 1;
    client.Timeout = 10000;
    client.Credentials = new NetworkCredential("myloginid@mail.com", "mypassword");
    mail.IsBodyHtml = true;
    mail.Subject = "New Job";

    mail.IsBodyHtml = true;
    try
    {

        client.Send(mail);
        mail.Dispose();
        Response.Redirect("thankyou.html");
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);

    }

When Print the exception got the following in ex:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.SendEmail(Object sender, EventArgs e)

1
looking at the exception message, it appears that the settings are incorrect for either the port, EnableSsl or the host smtp server. contact your provider for the correct settings.Ahmed ilyas

1 Answers

1
votes

If you want to use port 465, etc. you should set up client.EnableSsl = true

This configuration works for me:

    MailMessage message = new MailMessage
    {
      IsBodyHtml = true,
      Body = "text",
      Subject = "subject",
      To = { "firstmail@mail.com", "sfirstmail@mail.com" }
   };

   message.From = new MailAddress("sender@email.com");

   SmtpClient client = new SmtpClient("myhosting.secureserver.net", 465)
   {
      Credentials = new NetworkCredential("myloginid@mail.com", "mypassword"),
      EnableSsl = true
   };

   client.Send();