gpt4 book ai didi

c# - 无法通过 SendGrid 发送电子邮件

转载 作者:行者123 更新时间:2023-11-30 19:26:16 25 4
gpt4 key购买 nike

我正在遵循 SendGrid's site 中的示例作为凭据,我将他们在 Azure 门户中提供的内容粘贴到其中。尽管如此,我还是收到此错误消息。

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

我不清楚在这里做什么,甚至不知道如何调试它。我从桌面运行代码(在将其放到网站上之前),这样我就可以通过它自己设置断点。然而,没有高兴...

建议?

完整代码如下。

MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="64100b24011c05091408014a070b09" rel="noreferrer noopener nofollow">[email protected]</a>", "To Name"));
mailMsg.From = new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e98f9b8684a98c91888499858cc78a8684" rel="noreferrer noopener nofollow">[email protected]</a>", "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(
"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcddc6c9ced9e3929292fcddc6c9ced992dfd3d1" rel="noreferrer noopener nofollow">[email protected]</a>",
"LubX........pQc");
client.Credentials = credentials;
client.Send(mailMsg);

最佳答案

这是否是一个控制台应用程序?我一直在测试 SendGrid,发现当我尝试从控制台应用程序发送电子邮件时,电子邮件永远不会发送。但是,当我从网络应用程序尝试它(使用相同的发送代码)时,电子邮件被发送。我没有解释为什么控制台应用程序不起作用。

关于c# - 无法通过 SendGrid 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24111000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com