C# Can';t使用sendgrid api发送附件
我有一个字节[],它是我的ASP.NET Core 2.1应用程序中下载的pdf文件 我正在尝试将此作为附件附加到sendgrid电子邮件C# Can';t使用sendgrid api发送附件,c#,asp.net,asp.net-core,sendgrid,C#,Asp.net,Asp.net Core,Sendgrid,我有一个字节[],它是我的ASP.NET Core 2.1应用程序中下载的pdf文件 我正在尝试将此作为附件附加到sendgrid电子邮件 public async Task SendEmail(byte[] Attachment = null) { var client = new SendGridClient(apiKey); var msg = new SendGridMessage(); // I also set the To, Subject, body
public async Task SendEmail(byte[] Attachment = null)
{
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage();
// I also set the To, Subject, body etc etc
msg.AddAttachment("test.pdf",Convert.ToBase64String(Attachment) ,"application/pdf","inline");
var response = await client.SendEmailAsync(msg);
}
我得到一个“BadReqest”状态码。如果我删除AddAttachment行,则消息被接受
我做错了什么?试试这样的方法:
using (var stream = new MemoryStream(Attachment))
{
msg.AddAttachment("test.pdf", stream);
var response = await client.SendEmailAsync(msg);
}