Email HTML document, embedding images using c#

后端 未结 2 1470
野性不改
野性不改 2021-02-01 00:01

I need to send an email as a string in HTML format that has images embedded in it. I tried converting my images into base64 but it does not work.

The email h

2条回答
  •  执笔经年
    2021-02-01 00:36

    The other way to embed images in E-mail when using System.Net.Mail is to attach image from local drive to email and assign a contentID to it and later use this contentID in the image URL.

    That can be done like this:

    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 = "  ";
    

提交回复
热议问题