我将sendgrid设置为使用web api (而不是smtp中继)发送电子邮件。我遵循了C#上关于如何发送电子邮件的说明,包括创建api key环境变量和安装nuget package sendgrid。
在调用client.SendEmailAsync(msg)之后,返回的响应是"Accepted“,表示一切正常。但在我的测试电子邮件中没有收到任何电子邮件。
关闭Windows Defender防火墙后,发送了电子邮件。所以我认为防火墙阻止了我发送电子邮件?
我的问题是,如何在防火墙中为sendgrid添加例外设置,以允许来自sendgrid的外发电子邮件,或者是否在sendgrid或防火墙中都有我遗漏的配置?
代码:
var apiKey = Environment.GetEnvironmentVariable("SendGridApiKey");
var client = new SendGridClient(apiKey);
var from = new EmailAddress("test@example.com", "Example User");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("my_outlook_email_here", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);我将端口25和587添加到TCP和UDP的入站规则和出站规则中,以打开windows防火墙中的端口,但电子邮件仍无法发送。
发布于 2021-06-16 20:33:45
虽然这是一个老问题,但我的防火墙也有类似的问题。我不得不允许HTTPS从sendgrid服务器(传出接口)传输到我的DMZ (传入接口,我的网站所在的地方)。我的服务器54.155.98.0中用于sendgrid的地址。
https://stackoverflow.com/questions/57544008
复制相似问题