How to embed multiple images in email body using .NET

后端 未结 7 2245
孤城傲影
孤城傲影 2020-11-29 06:26

I\'m writing a program that sends emails to users with multiple images (charts) embedded in the Email message body (HTML).

When I tried the sample located here..whic

7条回答
  •  长情又很酷
    2020-11-29 06:42

    The other way to embed images in E-mail when using System.Net.Mail is

    Attach image from local drive to email and assign a contentID to it and later use this contentID in the image URL.

    This can be done by:

    var contentID = "Image";
    var inlineLogo = new Attachment(@"C:\Desktop\Image.jpg");
    inlineLogo.ContentId = contentID;
    inlineLogo.ContentDisposition.Inline = true;
    inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
    
    msg.IsBodyHtml = true;
    msg.Attachments.Add(inlineLogo);
    msg.Body = "  ";
    

提交回复
热议问题