public static void Run()
{
// ExStart:CreatingTNEFFromMSG
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Email();
// Create an instance of MailMessage and load an email file
MailMessage mailMsg = MailMessage.Load(dataDir + "EmailWithAttandEmbedded.eml");
// Extract Attachments from the message
foreach (Attachment attachment in mailMsg.Attachments)
{
// To display the the attachment file name
Console.WriteLine(attachment.Name);
// Save the attachment to disc
attachment.Save(attachment.Name);
// You can also save the attachment to memory stream
MemoryStream ms = new MemoryStream();
attachment.Save(ms);
}
// Extract Inline images from the message
foreach (LinkedResource lr in mailMsg.LinkedResources)
{
Console.WriteLine(lr.ContentType.Name);
lr.Save(lr.ContentType.Name);
}
}
}