I’m using SendGrid to send notifications to my sites users. If I try and send just 1 email at a time I have no problems, but if I start adding multiple emails to my list some don’t show up in the inboxes. Usually I just receive the 1st in the list.
I’m receiving a IsSuccessStatusCode
of true back from the sendEmailAsync()
call and
in my SendGrid activity dashboard it shows me that they’ve all been delivered, so I know they’re being sent and getting back a ok()
from the mail server.
Question – It seems like there might be something going on in the network or email providers with filtering, spam, etc. How would I know? The only thing I found was SendGrid troubleshooting link
Here is my code.
dynamic templateData = new JObject();
templateData.name = "Test";
templateData.text = "Testing";
templateData.buttonText = "Test";
templateData.buttonUrl = "Test";
// works!
var emails = new string[] {"[email protected]"};
// doesn't work!
var emails = new string[] {"[email protected]", "[email protected]", "[email protected]"};
// send email
_emailService.ExecuteTemplate(emails, "Test Subject" templateData);
// function
public async Task<Response> ExecuteTemplate(string[] toEmailAddresses, string subject, dynamic templateData) {
var client = new SendGridClient(sendGridOptions.SendGridKey);
SendGridMessage sendGridMessage = new SendGridMessage() {
From = new EmailAddress(_config["SendGrid:Server"], "Yogabandy"),
TemplateId = _config["SendGrid:TemplateId"]
};
templateData.subject = subject;
for (int i = 0; i < toEmailAddresses.Length; i++) {
sendGridMessage.AddTo(new EmailAddress(toEmailAddresses[i]), i);
sendGridMessage.SetTemplateData(templateData, i);
}
sendGridMessage.SetClickTracking(false, false);
sendGridMessage.SetOpenTracking(false);
sendGridMessage.SetGoogleAnalytics(false);
sendGridMessage.SetSubscriptionTracking(false);
var response = await client.SendEmailAsync(sendGridMessage);
if (response.IsSuccessStatusCode) {
_logger.LogInformation("Email queued");
} else {
_logger.LogError("Email not queued. Satus Code: " + response.StatusCode);
}
return response;
}