我需要以HTML格式发送一封包含嵌入式图片的字符串邮件。我试图将我的图片转换成base64
格式,但是并没有成功。
这个邮件有3个类型为System.Drawing.Image
的图片。我只需要在我的HTML格式字符串中获取它们。
我需要以HTML格式发送一封包含嵌入式图片的字符串邮件。我试图将我的图片转换成base64
格式,但是并没有成功。
这个邮件有3个类型为System.Drawing.Image
的图片。我只需要在我的HTML格式字符串中获取它们。
使用System.Net.Mail
发送邮件时,嵌入图片的另一种方式是将本地驱动器上的图像作为附件添加到电子邮件中,并为其分配一个contentID
,然后在图像URL中使用这个contentID
。
可以像下面这样完成:
msg.IsBodyHtml = true;
Attachment inlineLogo = new Attachment(@"C:\Desktop\Image.jpg");
msg.Attachments.Add(inlineLogo);
string contentID = "Image";
inlineLogo.ContentId = contentID;
//To make the image display as inline and not as attachment
inlineLogo.ContentDisposition.Inline = true;
inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
//To embed image in email
msg.Body = "<htm><body> <img src=\"cid:" + contentID + "\"> </body></html>";