private static void PrintMail(string fileName) { var stream = new StreamClass(); stream.Open(); stream.LoadFromFile(fileName); stream.Flush(); var mail = new MessageClass(); mail.DataSource.OpenObject(stream, "_Stream"); mail.DataSource.Save(); Console.WriteLine("From: {0}", mail.From); Console.WriteLine("To: {0}", mail.To); Console.WriteLine("CC: {0}", mail.CC); Console.WriteLine("BCC: {0}", mail.BCC); Console.WriteLine("Subject: {0}", mail.Subject); Console.WriteLine("Body:"); Console.WriteLine(mail.TextBody); Console.WriteLine(); Console.WriteLine("Attachments:"); foreach (IBodyPart attachment in mail.Attachments) { Console.Write(attachment.FileName); Console.Write(" Open it? [y/N] "); var key = Console.ReadKey(); Console.WriteLine(); if (key.KeyChar != 'Y' && key.KeyChar != 'y') continue; var tempFile = Path.Combine(Path.GetTempPath(), attachment.FileName); var contentStream = attachment.GetDecodedContentStream(); contentStream.SaveToFile(tempFile, SaveOptionsEnum.adSaveCreateOverWrite); Process.Start(tempFile); } stream.Close(); }
public void OpenEml(string filepath) { try { var stream = new StreamClass(); stream.Open(); stream.LoadFromFile(filepath); stream.Flush(); var mail = new MessageClass(); mail.DataSource.OpenObject(stream, "_Stream"); mail.DataSource.Save(); fromBox.Text = mail.From; toBox.Text = mail.To; ccBox.Text = mail.CC; bccBox.Text = mail.BCC; subjectBox.Text = mail.Subject; bodyBox.Text = mail.TextBody; attachmentsPanel.Controls.Clear(); foreach (IBodyPart attachment in mail.Attachments) { var linkLabel = new LinkLabel { Text = attachment.FileName, AutoSize = true, }; linkLabel.Links.Add(0, linkLabel.Text.Length, attachment.GetDecodedContentStream()); linkLabel.LinkClicked += LinkLabelLinkClicked; linkLabel.Disposed += LinkLabelDisposed; attachmentsPanel.Controls.Add(linkLabel); } stream.Close(); } catch (Exception) { MessageBox.Show(this, "An error occured while opening the file", "Email could not be opened", MessageBoxButtons.OK, MessageBoxIcon.Error); } }