【发布时间】:2020-10-03 23:34:52
【问题描述】:
我正在使用 SendGrid v3 API 和 C# 库 (v7) 发送电子邮件。 在我的电子邮件中,我有一个 png 标题。标头嵌入如下:
<img src="cid:emailheader"/>
在 C# 代码中,我将图像作为具有相同 ContentId 的附件发送
var mail = new Mail(发件人、主题、收件人、内容);
var headerPath = HttpContext.Current.Server.MapPath("~/Resources/email-header.png");
var attachment = new SendGrid.Helpers.Mail.Attachment();
attachment.ContentId = "emailheader";
attachment.Content = Convert.ToBase64String(File.ReadAllBytes(headerPath));
attachment.Type = "image/png";
attachment.Filename = "email-header.png";
mail.AddAttachment(attachment);
var send = sg.client.mail.send.post(requestBody: mail.Get());
然而,当我打开电子邮件时,它说找不到来源,即使图像正确显示在附件中
【问题讨论】:
-
我认为您需要将图像嵌入 HTML 邮件正文而不是作为附件。
-
我认为您需要在附加内容时设置
inline以将其与cid一起使用。见这里:github.com/sendgrid/sendgrid-csharp/blob/master/SendGrid/…