Please check it out. Basically, if you want to access any info about an email message, you can get a MailMessage instance firstly. Pop3Client and ImapClient all support to fetch message from server and cast into a MailMessage instance.
client.Connect(true); //connect to server, and auto login to it infos = client.ListMessages(); //list the messages in the server
if(infos != null) { for (int i = 0; i < infos.Count; i++) { MailMessage msg = client.FetchMessage(infos[ i ].SequenceNumber);//fetch message to local
foreach (Attachment att in msg.Attachments) //enumerate attachments in the message { Console.WriteLine(att.Name + " " + att.MediaType + " " + att.ContentType); } } }
2) for Imap
ImapClient client2 = new ImapClient("localhost", "testuser", "psw"); client2.Connect(true); //connect to server, and auto login to it client2.SelectFolder("Inbox"); //select the folder ImapMessageInfoCollection infos2 = null; infos2 = client2.ListMessages(); // list the messages if(infos2 != null) { for (int i = 0; i < infos2.Count; i++) { MailMessage msg = client2.FetchMessage(infos2[ i ].SequenceNumber); //fetch message to local
foreach (Attachment att in msg.Attachments) //enumerate attachements in the message { Console.WriteLine(att.Name + " " + att.MediaType + " " + att.ContentType); } } }
Could you please attach a sample file for which this is happenning. If you are reading email files after connecting to some mail server, you can save them to your disk by calling MailMessage.Save() method.
Sorry for the inconvenience. We are looking into this issue.
As a workaround, could you please try Aspose.Outlook.MapiMessage class. The following code snippet loads a file from disk and iterates through the attachments. You can also call FromStream() method to load the msg file from stream.
The MapiMessage object worked. thow a had to use the FromStream method, as my files is web based.
using (Stream stream = currentItem.File.OpenBinaryStream()) { //set to start of stream stream.Seek(0, SeekOrigin.Begin); //open the file as mapi message MapiMessage msg = MapiMessage.FromStream(stream); ........