I have a usecase where I have 1000 emails with the bodies prepared (they are ready to send as is), a single sent from email address, 1000 recipients. I am using SendGrid API v3 in C#. I am trying to figure out how to bulk send them to the SendGrid API. This is my code:
private async Task SendBatchEmails(DataRowCollection emailDataRows)
{
var WriteToDatabaseCollection = new Dictionary<Guid, string>();
var emailObjectCollection = new List<SendGridMessage>();
foreach (DataRow emailDataRow in emailDataRows)
{
var emailObject = new SendGridMessage();
var to = (new EmailAddress(emailDataRow["RecipientEmailAddress"] + "", emailDataRow["RecipientName"] + ""));
var from = new EmailAddress(emailDataRow["SenderEmailAddress"] + "", emailDataRow["SenderName"] + "");
var subject = emailDataRow["Subject"] + "";
var text = emailDataRow["MessageBody"] + "";
var html = $"<strong>{emailDataRow["MessageBody"] + "" }</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, text, html);
emailObjectCollection.Add(msg);
}
await emailClient.SendBatchEmailsEmailAsync(emailObjectCollection);
dataContext.UpdateEmailResult(WriteToDatabaseCollection);
}
public async Task SendBatchEmailsEmailAsync(List<SendGridMessage> messages)
{
return await client.????(messages);
}
client is a SendGridClient, and the only option I have is: SendEmailAsync(msg)
How do I send a batch fo sendgrid messages?