2015-10-04 47 views
0

我是新的ASP.Net並嘗試修復郵件問題。我的網站託管在godaddy服務器上,並在ASP.Net中開發。嘗試使用下面的腳本,但它的投擲的錯誤爲「發送郵件失敗」電子郵件不能在ASP.net上工作

MailMessage mail = new MailMessage("[email protected]", "[email protected]"); 
    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("[email protected]", "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); 

    } 

當打印異常得到了下面的前發送郵件:

System.Net.Mail.SmtpException : 郵件發送失敗。 ---> System.IO.IOException:無法從傳輸 連接讀取數據:net_io_connectionclosed。在在 系統 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字節[]緩衝液, 的Int32偏移的Int32讀,布爾的readLine)在 System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader 呼叫者,布爾ONELINE)。 Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader 呼叫者)在System.Net.Mail.CheckCommand.Send(SmtpConnection康恩, 字符串&響應)在System.Net.Mail.MailCommand.Send(SmtpConnection 康恩,字節[]命令,MailAddress from,Boolean allowUnicode)at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients,String deliveryNotify,Boolean allowUnicode,SmtpF ailedRecipientException &除外)在 System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE)---內 異常堆棧跟蹤的末尾在在 _Default System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE) .SendEmail(對象發件人,EventArgs的)

+2

查看異常消息,看起來設置對端口,EnableSsl或主機smtp服務器都是不正確的。請聯繫您的提供商以獲取正確的設置 –

回答

1

如果要使用端口465,等你應該建立client.EnableSsl = true

此配置爲我的作品:

MailMessage message = new MailMessage 
    { 
     IsBodyHtml = true, 
     Body = "text", 
     Subject = "subject", 
     To = { "[email protected]", "[email protected]" } 
    }; 

    message.From = new MailAddress("[email protected]"); 

    SmtpClient client = new SmtpClient("myhosting.secureserver.net", 465) 
    { 
     Credentials = new NetworkCredential("[email protected]", "mypassword"), 
     EnableSsl = true 
    }; 

    client.Send();