Image from MailMessage

0 votes
asked Jul 27, 2010 by John 2 (120 points)
edited Mar 22, 2011

Hi, I have in the example the following e-mail:

..
<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><img width=384 height=371 id="Bild_x0020_1"
src="cid:image001.png@xx.xx"><o:p></o:p></p>
..

How do I get the picture of this e-mail.

I call my mail such as:

..
Dim ML As New Pop3MessageCollection
Dim MM As MailMessage
..
MM = New MailMessage
MM = POP3.GetMailMessage(ML(x).SequenceNumber)
..
Dim HTMLPART as String = MM.BodyHtml

Thanks and regards

Applies to: Rebex Secure Mail

2 Answers

0 votes
answered Jul 27, 2010 by Lukas Pokorny (102,250 points)
edited Jul 27, 2010

You can find this picture in MailMessage object's Resources collection. This contains instances of LinkedResource whose ContentId.Id property is the "cid" value (such as "image001.png@xx.xx").

Sample code:

    Dim MM As MailMessage
    MM = POP3.GetMailMessage(ML(x).SequenceNumber)
    Dim HTMLPART As String = MM.BodyHtml

    For Each RESOURCE As LinkedResource In MM.Resources
        If Not RESOURCE.ContentId Is Nothing _
            And RESOURCE.ContentId.Id = "image001.png@xx.xx" Then

            ' do something with the resource
            RESOURCE.Save("image001.png")

        End If
    Next
0 votes
answered Jul 27, 2010 by John 3 (140 points)
edited Jul 27, 2010

Thank you very much, it works great.

...