【发布时间】:2021-06-01 12:10:34
【问题描述】:
我正在使用函数应用程序触发邮件,使用 MS Graph API,邮件正文文本被正确触发,但在呈现图片中显示的页眉和页脚图像时遇到问题。如何在body层面解决这个问题。
以下是以上图片在 HTML/Blob 文件中的引用
<img src=cid:Header.jpg>
<img src=cid:footer.png>
<ContentIDs>Header.jpg, footer.png</ContentIDs>
用于渲染主体的代码。
var mailContent = new Message
{
Subject = em.Subject,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = m.Body,
ODataType = null
},
ToRecipients = toEmails,
CcRecipients = ccEmails,
ODataType = null
};
编辑: 在此更改后,当前在 Function App 中面临错误请求。我正在努力解决这个问题。如果您在以下代码中发现任何差异,请随时发表评论。
var imagePath = @"<path\Header.jpg>";
var imageID = "Header.jpg";//file name
byte[] imageArray = System.IO.File.ReadAllBytes(imagePath);
var imagePath2 = @"<path\footer.png">;
var imageID2 = "footer.png";
byte[] imageArray2 =System.IO.File.ReadAllBytes(imagePath2);
var mContent = new Message
{
Subject = t.Subject,//parsing from the template
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = m.Body,
ODataType = "#microsoft.graph.fileAttachment"
},
ToRecipients = toEmails,
CcRecipients = ccEmails,
ODataType = "#microsoft.graph.fileAttachment",
HasAttachments = true,
Attachments = new MessageAttachmentsCollectionPage()
{
new FileAttachment
{
ContentBytes= imageArray,
ContentType = "image/jpeg",
ContentId= imageID,
IsInline=true,
Name = "theHead",
},
new FileAttachment
{
ContentBytes= imageArray2,
ContentType = "image/png",
ContentId= imageID2,
IsInline=true,
Name = "thefoot",
}
}
};
【问题讨论】:
-
怎么样?您的问题解决了吗?
-
嗨@StanleyGong 非常感谢您的回答。我从您的参考资料中获取了一些代码,但目前我在 Function App 中遇到了错误的请求。
-
我不确定这是否是重点,但似乎在代码的第 4 行丢失了
= -
抱歉在编辑过程中搞砸了,把它加回来。
-
我已经在我身边测试了你的代码,删除两行
ODataType = "#microsoft.graph.fileAttachment"后,你的代码对我有用
标签: c# azure-functions microsoft-graph-api office365 outlook-restapi