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