发送电子邮件我有这样的代码片段发送一封电子邮件,但我每次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端口的凭据,但仍然收到相同的错误。 –