How do I send an email With CC And BCC?
I am using .NET Core 3.1 and wrote this Send
method:
public async Task<Response> Send(string ToUser, string Subject, string TextContent, string HtmlContent, string base64context = null, string filename = "")
{
string apiKey = AppConfiguration.SendGridApiKey;
SendGridClient client = new SendGridClient(apiKey);
EmailAddress from = new EmailAddress(AppConfiguration.SendGridFromEmail, AppConfiguration.SendGridFromName);
EmailAddress toMail = new EmailAddress(ToUser);
SendGridMessage msg = MailHelper.CreateSingleEmail(from, toMail, Subject, TextContent, HtmlContent);
if(!string.IsNullOrWhiteSpace(base64context) && !string.IsNullOrWhiteSpace(filename))
{
msg.AddAttachment(filename, base64context);
}
return await client.SendEmailAsync(msg);
}
CodePudding user response:
As per SendGrid's documentation and source code, here's how:
SendGridMessage msg = new SendGridMessage();
msg.AddCc(new EmailAddress("[email protected]", "Example User1"));
msg.AddBcc(new EmailAddress("[email protected]", "Example User2"));