无法通过SendGrid发送电子邮件 [英] Can't send email through SendGrid

查看:250
本文介绍了无法通过SendGrid发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在跟踪 SendGrid的站点中的示例,并粘贴了凭据这是他们在Azure门户中给我的.不过,我仍然收到此错误消息.

I'm following the example from SendGrid's site and as credentials I'm pasting it what they gave me in the Azure portal. Still, I get this error message.

消息= {发送邮件失败."}
InnerException = {无法连接到远程服务器"}

Message = {"Failure sending mail."}
InnerException = {"Unable to connect to the remote server"}

我不清楚在这里做什么,甚至不清楚如何调试它.我正在从桌面上运行代码(在将其放到站点上之前),这样我就可以通过它打破自我.但是,没有喜悦...

I'm not clear on what to do here, not even how to debug it. I'm running the code from the desktop (before I put it on the site) so I can break-point myself through it. However, to no joy...

建议?

下面的完整代码.

MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("to@example.com", "To Name"));
mailMsg.From = new MailAddress("from@example.com", "From Name");
mailMsg.Subject = "subject";
string text = "text body";
string html = @"<p>html body</p>";
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(
  text, null, MediaTypeNames.Text.Plain));
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(
  html, null, MediaTypeNames.Text.Html));
SmtpClient client = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(
  "azure_...@azure.com",
  "LubX........pQc");
client.Credentials = credentials;
client.Send(mailMsg);

推荐答案

这是否恰好是控制台应用程序?我一直在测试SendGrid,发现当我尝试从控制台应用程序发送电子邮件时,永远不会发送电子邮件.但是,当我从Web应用程序尝试使用它(使用相同的精确发送代码)时,将发送电子邮件.我没有解释为什么控制台应用程序无法正常工作.

Does this happen to be a console application? I've been testing SendGrid and found that when I try to send an email from a Console application the emails are never sent. However, when I tried it from a web application (using the same exact sending code) the emails are sent. I have no explanation for why the console application does not work.

这篇关于无法通过SendGrid发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆