使用Sendgrid发送电子邮件发送失败?

时间:2016-04-28 05:41:46

标签: c# asp.net asp.net-mvc smtp sendgrid

我在过去2天内遇到此问题。电子邮件触发器正在使用SpecifiedPickupDirectory.But,如果我想实时实现它会产生以下错误,如下所述。
这是电子邮件失败的错误。 “邮件发送失败。”内部IOException“无法从传输连接读取数据:net_io_connectionclosed”。

这是我的代码,请检查

          MailMessage mailMsg = new MailMessage();
            mailMsg.To.Add(new MailAddress("smruti.m@xx.com", 

            // From
            mailMsg.From = new MailAddress("info@xx.com", "XXX");

            // Subject and multipart/alternative Body
            mailMsg.Subject = "SendGrid: Testing";
            string text = "Text Body";
            string html = @"<p>Testing HTML Body</p><p><li data-tb-region-item=""><a href=>AT&amp;T Profit Beats Expectations Despite Losing Television Subscribers </a></li></p>";
            mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
            mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

            // Init SmtpClient and send
            SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587));
            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("Userid", "Password");
            smtpClient.Credentials = credentials;

            smtpClient.Send(mailMsg);

0 个答案:

没有答案