【发布时间】:2021-06-23 03:25:30
【问题描述】:
我尝试发送电子邮件通知到列表、抄送列表和密件抄送列表,但我收到错误提示错误请求和成功代码为假。
如果我不添加抄送、密送列表,我可以发送电子邮件。你能帮我解决这个问题吗
var apiKey = "SG.xxxxxxxxxxxxxxxxxxxxxxxx"; //Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"); var client = new SendGridClient(apiKey); var msg = new SendGridMessage();
msg.From = new EmailAddress("xxxxxx@nidec-motor.com", "TechM");
msg.Subject = "Test email";
msg.PlainTextContent = "Sendgrid test email";
msg.HtmlContent = "<strong>Hello World!";
msg.Personalizations = new List<Personalization>
{
new Personalization
{
Tos = new List<EmailAddress>
{
new EmailAddress("xxxxxx@gmail.com", "Eswar"),
new EmailAddress("xxxx@techmahindra.com", "Test User-Eswar")
},
Ccs= new List<EmailAddress>()
{
new EmailAddress("xxxx@TechMahindra.com", "Eswar"),
new EmailAddress("xxxx@techmahindra.com", "Test User-Eswar")
},
Bccs=new List<EmailAddress>()
{
new EmailAddress("xxx@gmail.com", "Eswar"),
new EmailAddress("xxx@techmahindra.com", "Test User-Eswar")
}
}
};
var response = await client.SendEmailAsync(msg);
var test = response.IsSuccessStatusCode;
}
【问题讨论】:
-
你不能在抄送处传递空列表,例如:
Ccs= new List<EmailAddress>()吗? -
这里的问题是,为什么我无法发送带有 cc list 和 bcc list 的电子邮件?如果我删除 cc,bcc 列出它可以正常工作。