0 votes
by (220 points)

Hello support!

I'm starting to develop an application to read Pst Files (outlook) and convert them to Mime Message. I never had developed an app using Mime and I have one question related to embedded images in body message.

Follow my code to explanation:

 var MimeMessage = Message.Content.GetMessageFile().ConvertToMimeMessage();

            using (var Stream = new MemoryStream())
            {
                MimeMessage.Save(Stream);
                Stream.Position = 0;
                ImapMessage.Content.Load(Stream);

                return ImapMessage;
            }

The result is an email with almost all filled properties, except the images inline. I can see the inline content in Parts property but the final message does not contains the images. Inspecting the generated message, the image tag is correct but the image not is displayed.

... more content ...
    <p class=MsoNormal align=center style='text-align:center'><span
    style='color:black'><img border=0 width=573 height=217 id="Picture_x0020_2"
    src="cid:image003.jpg@01D1A45F.A330FC80"
    alt="cid:image003.jpg@01D11627.84DA7520"><o:p></o:p></span></p>
... more content ...

So, my doubt is how do I display the inline messages in a message body? I tried some ways to solve this problem and I have no idea to how to show images.

I appreciate any help to this question.

Regards.

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (73.5k points)

Hello,

please ensure two things:

  1. the linked image is stored in MailMessage.Resources collection not the MailMessage.Attachments.

  2. the linked resource has the ContentId property specified.

In your case, the code can look like this:

MailMessage mail = new MailMessage();

// fill mail properties
// ...

// add linked image to mail
var res = new LinkedResource("linked image source", MediaTypeNames.Image.Jpeg);
res.ContentId = "image003.jpg@01D1A45F.A330FC80";
mail.Resources.Add(res);

P.S: in your code, the src and alt values of the <img> tag differ.

by (220 points)
Hi Lukas.

Thank you for clarification about Attachments and Resources. I am newbie in those technologies and I am studying that right now. Anyway, I have one more question and I hope it's the last one.

The source code in your answer uses an instance of MailMessage class (Rebex.Mail.MailMessage) and I need to create an object of MimeMessage type (Rebex.Mail.MailMessage).

There is a native way to convert this objects? Sorry if is a basic or stupid question but I dont found any way to implement this and I need to create a MimeMessage object.

Thank you!
by (73.5k points)
Yes, it is possible to convert between those two:

    // convert MailMessage to MimeMessage
    MimeMessage mime = mail.ToMimeMessage();

    // convert MimeMessage to MailMessage
    MailMessage m = new MailMessage(mime);

Please note that maybe it is not necessary. The logic behind Rebex mail classes is following:
- MimeMesage represents a message in MIME format.
- MailMessage is abstraction of a general e-mail message (it is superset of all possible e-mail messages)

The MimeMessage is necessary if you have to use MIME format specific features. If not, it is more comfortable to use MailMessage.
...