链接的资源不是内嵌图像C#

时间:2015-06-08 10:52:21

标签: c# mailmessage

我写了下面的代码,用于将图像嵌入到从我的c#代码发送的邮件中。但是当我检查邮件时,我得到的图像就像附件而不是内嵌图像。 (Gmail的)

AlternateView htmlBodyView = null;

string htmlBody = "<html><body><h1></h1><br><img src=\"cid:SampleImage\"></body></html>";

AlternateView plainTextView = AlternateView.CreateAlternateViewFromString(htmlBody, null, "text/html");

ImageConverter ic = new ImageConverter();
Byte[] ba = (Byte[])ic.ConvertTo(bitmap_obj, typeof(Byte[]));
using (MemoryStream logo = new MemoryStream(ba))
{
    LinkedResource sampleImage = new LinkedResource(logo, "image/jpeg");
    sampleImage.ContentId = "sampleImage";

    htmlBodyView.LinkedResources.Add(sampleImage);

    p.SendEmail(htmlBodyView);
}

0 个答案:

没有答案