The following example demonstrates streaming an embedded image from an ASP.NET page to the browser. This is a useful technique for building web based email clients. Notice that although these are ASP.NET pages there ISN'T any HTML conent in the page. This is because the ASP.NET pages are streaming binary content to the browser.
[C#]
<%@ Page language="C#" %>
<%@ Import Namespace="aspNetMime"%>
<%@ Import Namespace="System.IO"%>
<script runat=server>
//notice that even though this is an ASP.NET page there ISN'T any HTML code on this page.
//that's because this page is meant to send binay content to the browser
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 = MimeMessage.ParseFile( Server.MapPath( filename ) );
//send the embedded part to the browser named 'My-Company-Logo'
MimePart embeddedPart = msg.GetEmbeddedPart("My-Company-Logo" );
if( embeddedPart != null )
{
//set the content type
if( embeddedPart.ContentType != null )
Response.ContentType = embeddedPart.ContentType.Value;
//stream the embedded part to the browser
embeddedPart.WriteToStream( Response.OutputStream );
}
}
</script>
[VB.NET]
<%@ Page language="vb" %>
<%@ Import Namespace="aspNetMime"%>
<%@ Import Namespace="System.IO"%>
<script runat=server>
'notice that even though this is an ASP.NET page there ISN'T any HTML code on this page.
'that's because this page is meant to send binay content to the browser
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 = MimeMessage.ParseFile( Server.MapPath( filename ) )
'send the embedded part to the browser named 'My-Company-Logo'
Dim embeddedPart As MimePart = msg.GetEmbeddedPart("My-Company-Logo")
If Not embeddedPart Is Nothing Then
'set the content type
If Not embeddedPart.ContentType Is Nothing Then
Response.ContentType = embeddedPart.ContentType.Value
End If
'stream the embedded part to the browser
embeddedPart.WriteToStream(Response.OutputStream)
End If
End Sub
</script>