andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

MailMessage in Attachement #75

Closed 537mfb closed 12 years ago

537mfb commented 12 years ago

This is more of a question than an issue as i am not sure if i am just missing something.

Today i got an e-mail wich had 2 attachements of type message/rfc822. An attachement of this type is another mail message that was sent as an attachement.

For the puposes of my program i need to extract certain attached files from the mail messages i get and handle them according to type of file. However, in this particular case, the files i needed to handle came as attachments inside those two attached mail messages, and as such, i couldn't find them and had to handle this work manually.

Is there a built-in way to turn an attachement of type message/rfc822 into an object of type MailMessage? if not, are there any plans to create one? Can anyone point me out a way to handle this type of situations (extract files from embeded mail messages) using the current setup?

Thanks

andyedinborough commented 12 years ago

The best method would be something like this:

var data = attachment.GetData();
var attachedMessage = new MailMessage();
using(var mem = new MemoryStream(data))
  attachedMessage.Load(mem);
537mfb commented 12 years ago

Great thanks a lot for the quick reply will try that code

537mfb commented 12 years ago

Well, since i seem to be using an older version that code didn't quite work (Load requiered a TextStream and MemStream isn't compatible with that - but your answer did take me in the right direction - i replaced your code with simply:

var attachedMesssage = new MailMessage();
attachedMessage.Load(attachement.Body);

thus using the other Load that receives the message as text

thanks again