1
我想發送一封電子郵件,每次我調用這個方法並嘗試發送它時,它會拋出一個錯誤「Failure Sending Mail。」。這不是很具描述性,我不確定哪一點甚至會失敗,因爲它經歷了所有的代碼,並且看起來沒問題。發送電子郵件 - 我哪裏錯了?
代碼:
public void SendEmail()
{
private string localhost = System.Net.Dns.GetHostName();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(strUserEmail);
//determine if the email sent was successful
if (blnFlag == true)
{
msg.Subject = "File Move was successful";
}
else
{
msg.Subject = "File Move";
}
msg.From = new System.Net.Mail.MailAddress(GlobalVars.strFromEmail);
msg.Body = strMessage;
SmtpClient client = new SmtpClient(localhost);
client.Send(msg);
}
你嘗試把斷點並調試? –
你在你的機器上運行SMTP服務嗎? – AnthonyLambert
你能告訴我們'localhost'嗎? – tnw