如何在.net Core 3.1和c#中使用SendGrid发送电子邮件中添加抄送或密件



如何使用抄送和密件发送邮件?我使用。net Core 3.1编写了以下Send方法:

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);
}

根据SendGrid的文档和源代码,如下所示:

SendGridMessage msg = new SendGridMessage();
msg.AddCc(new EmailAddress("test1@example.com", "Example User1"));          
msg.AddBcc(new EmailAddress("test2@example.com", "Example User2"));

最新更新