Inline-Images in Eml-Files not working

hi,
I’m trying hard to create a mailmessage in EML-Format. I’ve already tried working with attachments, linkedresources, adding alternate views, using sethtmlbody.

I’ve seen the example in the documentation:

and tried it. But it doesn’t work. the inline-image isn’t visible.

can you please provide a working example.

Hello @smartcrm,

Please ensure that you are using the latest version of Aspose.Email and that the path to the image and the file name, including its extension, are correct.

We have tested with the following code, which works as expected:

var eml = new MailMessage
{
    From = "AndrewIrwin@from.com",
    To = "SusanMarc@to.com",
    Subject = "This is an email"
};

var plainView =
    AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain");

var htmlView =
    AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:myimage>", null,
        "text/html");

var barcode = new LinkedResource(@"image.png", MediaTypeNames.Image.Jpeg)
{
    ContentId = "myimage"
};

eml.LinkedResources.Add(barcode);
eml.AlternateViews.Add(plainView);
eml.AlternateViews.Add(htmlView);

eml.Save(@"EmbeddedImage_out1.eml", SaveOptions.DefaultEml);

This should work correctly.

Please also make sure that the cid in the <img> tag and the ContentId property of the LinkedResource must match exactly for the image to be embedded correctly.

hi,
I’ve tried your code once again. And it still doesn’t work. Neither Classic Outlook, New Outlook (which would be my goal) or https://www.emlreader.com/ does show the image.
The source image surly exists. And according to the base64 in the eml it’s present.

I’ve attached the eml-File and a screenshot from the new outlook.
sample.zip (44.4 KB)

@smartcrm,

Thank you for providing further details and the sample file. Your email is correct.

We tested the file in various mail clients and observed the issue only in the new version of Outlook. The image displays correctly in earlier versions of Outlook and email clients such as Thunderbird.

The new Outlook displays the image if the image data is embedded directly into the HTML as a base64 string. For example:

var eml = new MailMessage
{
    From = "AndrewIrwin@from.com",
    To = "SusanMarc@to.com",
    Subject = "This is an email"
};

var plainView =
    AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain");

var dataInBase64 = Convert.ToBase64String(File.ReadAllBytes(@"image.jpg")); 

var htmlView =
    AlternateView.CreateAlternateViewFromString($"Here is an embedded image.<img src=data:image/jpeg;base64,{dataInBase64}>", null, 
        "text/html");

eml.AlternateViews.Add(plainView);
eml.AlternateViews.Add(htmlView);

eml.Save(@"out.eml", SaveOptions.DefaultEml);

This behavior of the new Outlook seems unusual, as it does not align with the commonly accepted method of using Content-ID for linked resources.

Please check the suggested code snippet with base64 embedding and share your findings. If you continue to experience issues, let us know, and we’ll further investigate.