[英]How to Add CC or Bcc in Send Email With SendGrid in .NET Core 3.1 and C#
How do I send an email With CC And BCC?如何使用 CC 和 BCC 发送 email? I am using .NET Core 3.1 and wrote this
Send
method:我正在使用 .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);
}
As per SendGrid's documentation and source code , here's how:根据SendGrid 的文档和源代码,方法如下:
SendGridMessage msg = new SendGridMessage();
msg.AddCc(new EmailAddress("test1@example.com", "Example User1"));
msg.AddBcc(new EmailAddress("test2@example.com", "Example User2"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.