Issue with Gmail - Embedded images using MailKit

前端 未结 1 1406
粉色の甜心
粉色の甜心 2021-01-27 04:49

I\'m trying to send emails with embedded images using MailKit. It works well on MS Outlook. However, images do not display as embedded images in Gmail. I tried to attach with \"

相关标签:
1条回答
  • 2021-01-27 05:40

    Well, first of all, why are you creating System.Net.Mail objects and then simply disposing them without using them in any way?

    See this code for what I mean:

    LinkedResource inline = new LinkedResource(new MemoryStream(imageData), Image.Jpeg)
    {
        ContentId = contentId,
        TransferEncoding = TransferEncoding.Base64,
        ContentLink = new Uri("cid:" + contentId),
    };
    inline.ContentType.Name = contentId;
    inline.ContentType.MediaType = Image.Jpeg;
    

    Let's try this instead:

    var contentType = new ContentType ("image", "jpeg");
    var contentId = MimeKit.Utils.MimeUtils.GenerateMessageId ();
    var image = (MimePart) bodyBuilder.LinkedResources.Add (file, contentType);
    image.ContentTransferEncoding = ContentEncoding.Base64;
    image.ContentId = contentId;
    
    item.SetAttributeValue ("src", "cid:" + contentId);
    
    0 讨论(0)
提交回复
热议问题