Sending an Embedded Image to an ASP.NET Response Stream.

aspNetMime has the powerful capability to write content directly to the Response stream of an ASP.NET page. This example demonstrates finding an embedded image in the email named "My-Company-Logo". aspNetMime then sets the content-type of the ASP.NET page equal to the content-type of the image. aspNetMime then writes the binary content of the image directly to Response stream. Notice, that on the ASP.NET pages NO HTML code exists, as these pages only send binary image data to the browser.

[C#]

//create a new pop3 object POP3 pop = new POP3("127.0.0.1","dave@blah.com", "mypassword" ); //connect to the POP3 server pop.Connect(); MimeMessage msg = pop.GetMessage(1); //get the embedded image named "My-Company-Logo" MimePart embeddedPart = msg.GetEmbeddedPartByCID( "My-Company-Logo" ); //set the page contentType to match the content-type of the image if( ( embeddedPart.ContentType != null ) && ( embeddedPart.ContentType.Value.Length>0 ) ) Response.ContentType = embeddedPart.ContentType.Value; //now write the image directly to the Response stream embeddedPart.WriteToStream( Response.OutputStream ); pop.Disconnect();


[VB.NET]

'create a new pop3 object Dim pop As New POP3("127.0.0.1", "dave@blah.com", "mypassword") 'connect to the POP3 server pop.Connect() Dim msg As MimeMessage = pop.GetMessage(1) 'get a embedded image named "My-Company-Logo" Dim embeddedPart As MimePart = msg.GetEmbeddedPartByCID("My-Company-Logo") 'set the page contentType to match the content-type of the image If Not (embeddedPart.ContentType Is Nothing) And embeddedPart.ContentType.Value.Length > 0 Then Response.ContentType = embeddedPart.ContentType.Value End If 'now write the image directly to the Response stream embeddedPart.WriteToStream(Response.OutputStream) pop.Disconnect()