编辑:我能够发送邮件,而附件发送邮件带有附件
收到此错误尝试发送邮件:
System.Net.Mail.SmtpException: The operation has timed out.
以下是我的代码:
public static void SendMailMessage(string to, string subject, string body, List<string> attachment)
{
MailMessage mMailMessage = new MailMessage();
// string body; --> Compile time error, body is already defined as an argument
mMailMessage.From = new MailAddress("[email protected]");
mMailMessage.To.Add(new MailAddress(to));
mMailMessage.Subject = subject;
mMailMessage.Body = body;
foreach (string s in attachment)
{
var att = new Attachment(s);
mMailMessage.Attachments.Add(att);
}
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.High;
using (SmtpClient mSmtpClient = new SmtpClient())
{
mSmtpClient.Send(mMailMessage);
}
}
Web配置
<system.net>
<mailSettings>
<smtp from="mailid">
<network host="smtp.gmail.com" port="587" enableSsl="true" userName="username" password="pass" />
</smtp>
</mailSettings>
注:附件不超过(低于25 MB)的限制
我能做些什么来解决这个问题,还是我缺少什么?
超时可能表示无法连接到邮件服务器。 – 2013-03-06 14:26:32
gmail smtp不太可能离线,因此请尝试将enableSsl设置为false并进行测试。我相信他们使用TLS代替SSL发送 – TimothyP 2013-03-06 14:27:18
好吧,显然你应该确实将ssl设置为true,你是否曾尝试从正在运行该软件的PC打开一个到SMTP的原始会话? – TimothyP 2013-03-06 14:30:50