3
我使用此代码从Web应用程序发送电子邮件。没有问题,只有一个收件人。我研究过使用与https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/csharp.html相同的技术将电子邮件发送给多个收件人。我试图用逗号分隔的字符串作为destinatario(请参阅代码中的参数),即“[email protected],[email protected],[email protected]”,但SendGrid仅接收第一个接收者。我也尝试过使用数组,但结果是相似的,SG仅使用最后一个接收者。什么是通过收件人列表的正确方法?sendgrid多个收件人c#
public class email
{
public void enviar(string destinatario, string asunto, string contenido)
{
Execute(destinatario, asunto, contenido).Wait();
}
static async Task Execute(string destinatario, string asunto, string contenido)
{
string apiKey = "SG...............";
dynamic sg = new SendGridAPIClient(apiKey);
Email from = new Email("[email protected]");
string subject = asunto;
Email to = new Email(destinatario);
Content content = new Content("text/plain", contenido);
Mail mail = new Mail(from, subject, to, content);
dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
}
}
请勿使用'Task.Wait()'。它会造成死锁。你需要在任何地方使用'async'。 (并且不要使用'async void') – SLaks
也不要使用'dynamic'。 – SLaks