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";

//this creates a MimeMessage from a file
aspNetMime.MimeMessage msg = aspNetMime.MimeMessage.ParseFile( filename );

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