Home | Contact Us | Download | Support | Purchase | Shopping Cart | Products


Product List
  "[in response to a support question]Now that's service!!!!!! We will definitely recommend you and your products whenever possible...your service is top notch!!!"
Thomas Stettner
Law School Administration Council
 
More
Testimonials

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#]

<%@ Page language="c#" %>
<%@ Import Namespace="aspNetPOP3"%>
<%@ Import Namespace="aspNetMime"%>

<script runat=server>

		private void Page_Load(object sender, System.EventArgs e)
		{
			//create a new pop3 object
			POP3 pop = new POP3("127.0.0.1","dave@blah.com", "mypassword" );
            
			//connect to the POP3 server
			pop.Connect();
                        	
			//get the message with embedded images
			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();

		}

</script>

 

[VB.NET]

<%@ Page language="VB" %>
<%@ Import Namespace="aspNetPOP3"%>
<%@ Import Namespace="aspNetMime"%>

<script runat=server>


Private Sub Page_Load(sender As Object, e As System.EventArgs)
   '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 the 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()
End Sub 


</script>

 

 



The box is not shipped. aspNetPOP3 is a downloadable product.