发送带附件的邮件

编辑我可以发送没有附件的邮件

尝试发送邮件时出现此错误:

System.Net.Mail.SmtpException: The operation has timed out. 

以下是我的代码:

 public static void SendMailMessage(string to, string subject, string body, List attachment) { MailMessage mMailMessage = new MailMessage(); // string body; --> Compile time error, body is already defined as an argument mMailMessage.From = new MailAddress("abc@gmail.com"); 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配置

        

注意:附件不超过其限制(低于25 mb)

我该怎么做才能解决这个问题,或者我错过了什么?

所以基本上我们在聊天期间发现问题出现是因为上传附件需要很长时间。

解决它的一种方法是增加SmtpClient的超时值:

 mSmtpClient.Timeout = int.MaxValue; 

注意:使用int.MaxValue进行测试,但为部署的解决方案使用更实际的值。

设置本地smtp服务器以进行中继,或使用类似http://aws.amazon.com/ses/的内容 。 我不认为谷歌会允许你通过他们的服务器进行程序化中继。