【发布时间】:2016-02-21 21:23:13
【问题描述】:
自从最近将项目升级到 .net 4.5.2 后,我通过 SendGrid 发送电子邮件时遇到异常
发送邮件失败。 System.IO.IOException:无法从中读取数据 传输连接:net_io_connectionclosed。在 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字节 [] 缓冲区, Int32 偏移,Int32 读取,布尔读取线)在 System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader 调用者,布尔 oneLine)在 System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader 调用者)在 System.Net.Mail.CheckCommand.Send(SmtpConnection conn, 字符串和响应)在 System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] 命令, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(邮件地址发件人, MailAddressCollection 收件人,字符串 deliveryNotify,布尔值 allowUnicode、SmtpFailedRecipientException& 异常)在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)在 SendGridMail.Transport.SMTP.SmtpWrapper.Send(MailMessage mime) 在 SendGridMail.Transport.SMTP.Deliver(ISendGrid 消息)在 ReACT.Classes.Business.Helpers.Email.Send(String[] to, String[] toNames, Boolean ccToSender, String[] ccTo, String[] ccToNames, String 主题,字符串正文,布尔 isHtml,字符串 SMTPServer,字符串 EmailUserName,字符串 EmailPassword,字符串 EmailPort,字符串 SystemEmailAddress, String SystemEmailName, String& FriendlyException, 字符串&技术异常)
使用 SendGrid 服务通过 SMTP 发送电子邮件的代码如下 -
SendGridMail.SendGrid vEmailMessage = SendGridMail.SendGrid.GetInstance(vMailMessage.From, vMailMessage.To.ToArray(), vMailMessage.CC.ToArray(), new MailAddress[0], vMailMessage.Subject, vMailMessage.Body, vMailMessage.Body);
NetworkCredential vCredentials = new NetworkCredential(this.ApplicationSettings.EmailUserName, this.ApplicationSettings.EmailPassword);
var vTransport = SMTP.GetInstance(vCredentials);
//Send email message
vTransport.Deliver(vEmailMessage);
凭据正确并确认工作正常。这个问题从 .net 框架升级后才开始出现,不幸的是,我们无法降级回目标 .net 4
【问题讨论】: