我有一個代碼,我正在發送郵件。當我在本地主機郵件上發送郵件時,可以輕鬆發送郵件,但是當我將代碼上傳到服務器。我得到這個例外在服務器上獲取異常SMTP服務器需要安全連接或客戶端未通過認證
System.Net.Mail.SmtpException: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.5.1 Authentication Required. Learn more at at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,
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) at
Admin_test.Page_Load(Object sender, EventArgs e) in
d:\hostingspaces\abd9009\ihmsgr.domainNames.net\wwwroot\info\test.aspx.cs:line
29
我的代碼完美運行我的本地機器上,而其他服務器,但在服務器上 不起作用上是這樣的:
protected void Page_Load(object sender, EventArgs e)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]", "Email
head", System.Text.Encoding.UTF8);
mail.Subject = "This mail is send from asp.net application";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new
System.Net.NetworkCredential("[email protected]", "MyPassword");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex);
}
}
我使用的服務器http://www.arvixe.com/上主機空間請幫助
儘快刪除此內容,並且不會傳播您的GMAIL用戶名和密碼! – Haney
修改親愛的虛擬用戶名和密碼 – user3563009
您仍然可以在修訂歷史記錄FYI中看到您的密碼。此時可能最容易更改密碼。您應該學習如何使用wireshark和telnet實際調試smtp流量,因爲您可能會遇到其他問題。 –