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";
//this creates a MimeMessage from a file
aspNetMime.MimeMessage msg = new aspNetMime.MimeMessage.ParseFile( Server.MapPath( filename ) );
//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" 'this creates a MimeMessage from a file Dim msg As aspNetMime.MimeMessage = aspNetMime.MimeMessage.ParseFile( Server.MapPath( filename ) );
'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>