[C#]
//an email on the filesystem string filename = "testEmail.eml"; //open the email FileStream fs = File.Open( filename, FileMode.Open ); //this creates a Message from a stream aspNetMime.Message msg = new aspNetMime.Message( fs ); //close the stream fs.Close(); foreach( Header h in msg.Headers ) { Console.WriteLine( "Name -- " + h.Name ); Console.WriteLine( "Value -- " + h.Value ); Console.WriteLine( "Complete Value (includes parameters) -- " + h.ValueComplete ); Console.WriteLine( "The raw header -- " + h.RawValue ); } Console.WriteLine( "done..." ); Console.ReadLine();
[Visual Basic]
'an email on the filesystem Dim filename As String = "testEmail.eml" 'open the email Dim fs As FileStream = File.Open(filename,FileMode.Open) 'this creates a Message from a stream Dim msg As aspNetMime.Message = New aspNetMime.Message(fs) 'close the stream fs.Close() Dim h As Header For Each h In msg.Headers Console.WriteLine("Name -- " + h.Name) Console.WriteLine("Value -- " + h.Value) Console.WriteLine("Complete Value (includes parameters) -- " + h.ValueComplete) Console.WriteLine("The raw header -- " + h.RawValue) Next Console.WriteLine("done...") Console.ReadLine()
//an email on the filesystem string filename = "testEmail.eml"; //open the email FileStream fs = File.Open( filename, FileMode.Open ); //this creates a Message from a stream aspNetMime.Message msg = new aspNetMime.Message( fs ); //close the stream fs.Close(); //access different headers Header h = msg.GetHeader( "Status" ); //check for a status header if( h != null ) Console.WriteLine( h.RawValue ); //check for a X-header "X-Organization" //the GetXHeader() method will find headers that start with X- h = msg.GetXHeader( "Organization "); if( h!= null ) Console.WriteLine( h.RawValue ); //check for X-OriginalArrivalTime h = msg.GetXHeader( "OriginalArrivalTime" ); if( h != null ) Console.WriteLine( h.RawValue ); Console.WriteLine( "done..." ); Console.ReadLine();
'an email on the filesystem Dim filename As String = "testEmail.eml" 'open the email Dim fs As FileStream = File.Open(filename,FileMode.Open) 'this creates a Message from a stream Dim msg As aspNetMime.Message = New aspNetMime.Message(fs) 'close the stream fs.Close() 'access different headers Dim h As Header = msg.GetHeader("Status") 'check for a status header If Not h Is Nothing Then Console.WriteLine(h.RawValue) End If 'check for a X-header "X-Organization" 'the GetXHeader() method will find headers that start with X- h = msg.GetXHeader("Organization ") If Not h Is Nothing Then Console.WriteLine(h.RawValue) End If 'check for X-OriginalArrivalTime h = msg.GetXHeader("OriginalArrivalTime") If Not h Is Nothing Then Console.WriteLine(h.RawValue) End If Console.WriteLine("done...") Console.ReadLine()
//an email on the filesystem string filename = "testEmail.eml"; //open the email StreamReader sr = new StreamReader( filename ); //read the stream into some text string mytext = sr.ReadToEnd(); //close the stream sr.Close(); //this creates a Message from a stream aspNetMime.Message msg = new aspNetMime.Message( myte //get the attachments and loop through them MimePartCollection attachments = msg.Attachments; foreach( MimePart attachment in attachments ) { Console.WriteLine( attachment.AttachmentName() ); } Console.WriteLine( "done..." ); Console.ReadLine();
'an email on the filesystem Dim filename As String = "testEmail.eml" 'open the email Dim sr As StreamReader = New StreamReader(filename) 'read the stream into some text Dim mytext As String = sr.ReadToEnd() 'close the stream sr.Close() 'this creates a Message from a stream aspNetMime.Message msg = New aspNetMime.Message(myte 'get the attachments and loop through them Dim attachments As MimePartCollection = msg.Attachments Dim attachment As MimePart For Each attachment In attachments Console.WriteLine(attachment.AttachmentName()) Next Console.WriteLine("done...") Console.ReadLine()
<%@ 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 //binary content (the attachment) to the browser 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.Message msg = new aspNetMime.Message( emailContents ); //send the first attachment to the browser if( msg.Attachments.Count > 0 ) { //get the first attachment MimePart attachment = msg.Attachments[0]; //check to see if the attachment has a Content-Type, and if the Content-Type is an image //if it is an image, then stream it directly to the brower. if( ( attachment.ContentType != null ) && ( attachment.ContentType.Value.IndexOf( "image" )>-1 ) ) { Response.ContentType = attachment.ContentType.Value; attachment.WriteToStream( Response.OutputStream ); } else { //this method should open the //"Save File As" dialog box in the browser //set the Content-Type as an attachment Response.ContentType = "APPLICATION/OCTET-STREAM"; //set the filename Response.AddHeader( "Content-Disposition", "attachment;filename=\"" + attachment.AttachmentName() + "\"" ); attachment.WriteToStream( Response.OutputStream ); } } } </script>
<%@ 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 'binary content (the attachment) 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" '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.Message = New aspNetMime.Message(emailContents) 'send the first attachment to the browser If msg.Attachments.Count > 0 Then 'get the first attachment Dim attachment As MimePart = msg.Attachments(0) 'check to see if the attachment has a Content-Type, and if the Content-Type is an image 'if it is an image, then stream it directly to the brower. If (Not attachment.ContentType Is Nothing) AND (attachment.ContentType.Value.IndexOf("image")>-1) Then Response.ContentType = attachment.ContentType.Value attachment.WriteToStream(Response.OutputStream) Else 'this method should open the '"Save File As" dialog box in the browser 'set the Content-Type as an attachment Response.ContentType = "APPLICATION/OCTET-STREAM" 'set the filename Response.AddHeader("Content-Disposition", "attachment;filename=\"" + attachment.AttachmentName() + "\"") attachment.WriteToStream(Response.OutputStream) End If End If End Sub </script>
//an email on the filesystem string filename = "testEmail.eml"; //open the email FileStream fs = File.Open( filename, FileMode.Open ); //this creates a Message from a stream aspNetMime.Message msg = new aspNetMime.Message( fs ); fs.Close(); MimePartCollection attachments = msg.Attachments; foreach( MimePart mp in attachments ) { Console.WriteLine( mp.AttachmentName() ); } Console.WriteLine( "done..." ); Console.ReadLine();
'an email on the filesystem Dim filename As String = "testEmail.eml" 'open the email Dim fs As FileStream = File.Open(filename, FileMode.Open) 'this creates a Message from a stream Dim msg As New aspNetMime.Message(fs) fs.Close() Dim attachments As MimePartCollection = msg.Attachments Dim mp As MimePart For Each mp In attachments Console.WriteLine(mp.AttachmentName()) Next mp Console.WriteLine("done...") Console.ReadLine()
Copyright 2003 - Contact: Webmaster Last Updated: Monday, June 10, 2013