Home | Demo | Contact Us | Download | Support | Purchase | Products


Other Products
 
  "Thanks, Dave. You rule. Great product."
Jeff
HR Imaging Partners
 
More
Testimonials

Stream Text to the Browser

The following example checks the Mime message for a default textual part by using msg.MainBodyPart. MainBodyPart will return the HTML part (if one exists). If the HTML part doesn't exist, the TEXT part is returned.

 

This technique for streaming text to the browser is useful for resolving non-ascii charset messages.


[C#]

<%@ Page language="c#" %>
<%@ Import Namespace="aspNetMime"%>
<%@ Import Namespace="System.IO"%>

<script runat=server>
		
		private void Page_Load(object sender, System.EventArgs e)
		{


			//an email on the filesystem
			string filename = "testEmail.eml";

			//open the email
			StreamReader sr = new StreamReader( Server.MapPath( filename ) );
			string emailContents = sr.ReadToEnd();
			sr.Close();

			//this creates a Message from a stream
			aspNetMime.MimeMessage msg = new aspNetMime.MimeMessage( emailContents );

			//send the main body part text to the browser
			MimePart body = msg.MainBodyPart;

			if( body != null )
			{
				//set the charset
				Response.Charset = body.GetCharSet();
				
				//write the body part to the response stream
				body.WriteToStream( Response.OutputStream   );
			}
			else
			{
				Response.Write( "no textual body part found.");
			}


		}
				

</script>

 

[VB.NET]

<%@ Page language="vb" %>
<%@ Import Namespace="aspNetMime"%>
<%@ Import Namespace="System.IO"%>

<script runat=server>
		Private  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
 
 
			'an email on the filesystem
			Dim filename As String =  "testEmail.eml" 
 
			'open the email
			Dim sr As StreamReader =  New StreamReader(Server.MapPath(filename)) 
			Dim emailContents As String =  sr.ReadToEnd() 
			sr.Close()
 
			'this creates a Message from a stream
			Dim msg As aspNetMime.MimeMessage =  New aspNetMime.MimeMessage(emailContents) 
 
			'send the main body part text to the browser
			Dim body As MimePart =  msg.MainBodyPart 
 
			If Not body Is Nothing Then
				'set the charset
				Response.Charset = body.GetCharSet()
 
				'write the body part to the response stream
				body.WriteToStream(Response.OutputStream  )
			Else 
				Response.Write("no textual body part found.")
			End If
 
 
		End Sub



</script>

 

 

 



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