ramthechosenone
9/3/2019 - 3:20 PM

SendGrid C# Multiple emails

//npm below
using SendGrid;
using SendGrid.Helpers.Mail;

//code
var apiKey = config["SendGridApiKey"];
var sgClient = new SendGridClient(apiKey);
var from = new EmailAddress(config["FromEmail"]);
var subject = "Activity Summary report for " + config["client"];

var tos = new List<EmailAddress>{
    new EmailAddress(config["DevToEmail"]),
    new EmailAddress(config["Client]")
};
var plainTextContent = new StringBuilder();


var missingActivitiesListHtml = "<ul>";

missingActivitiesListHtml = "</ul>";

var body = "";
body = "<div>Hi</div>";
body += "<p>Activity completion report in the past 7 days<br/>";
body += "<br/>Total number of courses -- "+totalOrders+ " <br/> Completed activities -- " + capturedCompletions + "<br/> Probable missing activities --" + missingActivityList.Count + " <br/> Processing or Yet to complete ones -- " + yetToProcess + "";
body += "<br/>Missing ones are below:";
body += "<br/>"+ missingActivitiesListHtml;
body += "</p>";
body += "Thanks, <br/>Activity Summarizer";
plainTextContent.AppendLine(body);

var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, tos, subject, plainTextContent.ToString(), plainTextContent.ToString());
var response = await sgClient.SendEmailAsync(msg);
log.Info($"Email sent to - {tos}");