發送電子郵件我有這樣的代碼片段發送一封電子郵件,但我每次EXCUTE它的時候,我得到這個例外通過谷歌
等待操作期限屆滿
public static void CreateTimeoutTestMessage(string server)
{
string to = "[email protected]";
string from = "[email protected]";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient(server, 587);
client.EnableSsl = true;
client.Credentials=new NetworkCredential("[email protected]", "XXXXXXXXX");
Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
client.Timeout = 100;
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTimeoutTestMessage(): {0}",
ex.ToString());
}
Console.ReadLine();
}
提示:您正嘗試通過Gmail的SMTP服務器發送郵件,而不提供您嘗試發送的帳戶的憑據。您還沒有爲GMail的SMTP服務器(它的'587' IIRC)指定正確的端口..您應該在這裏查看類似的問題以獲得您需要的答案。 –
請閱讀手冊:https://support.google.com/mail/answer/78775?hl=zh-CN –
我添加了帳戶和gmail端口的憑據,但仍然收到相同的錯誤。 –