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


Other Products
 
  "Sweet, that worked thank you so much for your help solving this problem. I have to say that your company has some of the best customer service I have ever worked with. Thank you again for all your help."
J. Shore
DePauw University
 
More
Testimonials

Loop through Attachments and Embedded Parts

The following example demonstrates looping through the attachments and embedded parts that may be part of a mime message.


[C#]

//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.MimeMessage msg = new aspNetMime.MimeMessage( myte

//get the attachments and loop through them
MimePartCollection attachments = msg.Attachments;
foreach( MimePart attachment in attachments )
{
	Console.WriteLine( attachment.AttachmentName() );
}

//now loop through any embedded images or objects
MimePartCollection embeddedParts = msg.EmbeddedParts;
foreach( MimePart part in embeddedParts )
{
	Console.WriteLine( part.EmbeddedName() );
}

Console.WriteLine( "done..." );
Console.ReadLine();


 

[VB.NET]

'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.MimeMessage msg = New aspNetMime.MimeMessage(mytext)
 
'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
 
'now loop through any embedded images or objects
Dim embeddedParts As MimePartCollection =  msg.EmbeddedParts 
Dim part As MimePart
For Each part In embeddedParts
	Console.WriteLine(part.EmbeddedName())
Next
 
Console.WriteLine("done...")
Console.ReadLine()


 

 

 



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