由於上述錯誤,導致在client.Send(email);
處發生崩潰並崩潰。四重檢查一切。System.Net.Mail.SmtpException {「發送電子郵件失敗。」}
這裏是我的代碼:
private void submit_Click(object sender, RoutedEventArgs e)
{
string from = "************@gmail.com";
string to = "*******@sru.edu";
string subject = "PSLM Test";
string body = "PSLM Test";
string server = "smtp.gmail.com";
int port = 465;
string username = "************";
string password = "*******";
SmtpClient client = new SmtpClient(server, port);
client.Credentials = new NetworkCredential(username, password);
MailMessage email = new MailMessage(from, to, subject, body);
email.Attachments.Add(new Attachment(GlobalVariables.attachedFilePath));
email.Attachments.Add(new Attachment(GlobalVariables.formsAndTemplatesPath[0]));
email.Attachments.Add(new Attachment(GlobalVariables.formsAndTemplatesPath[1]));
email.Attachments.Add(new Attachment(GlobalVariables.formsAndTemplatesPath[2]));
client.Send(email);
}
什麼我做錯了嗎?
什麼是底層錯誤?檢查你捕獲異常的'InnerException'屬性。 – lorond
_總是檢查['InnerException'屬性](https://msdn.microsoft.com/en-us/library/windows/apps/system.exception.innerexception)。 –
我怕這不是我們可以簡單地指出你的代碼中的錯誤,它將與你的郵件服務器的設置有關。您是否檢查過'InnerException',其中可能包含有關實際問題的更多詳細信息 – Jamiec