Save Attachment + Email in eml file

Apr 26, 2014 at 12:07 PM
Hi, I want to create the copy of my email + attachment in an eml file. So what should i write for that.
Coordinator
Apr 27, 2014 at 2:31 PM
Previous version
var rawText = File.ReadAllText("C:/yourMail.eml");
var mg = new MailMessage(rawText);
mg.Contents[0].DecodeData("C:/Temp/copyOfContent.png");

Latest version
var rawBytes = File.ReadAllBytes("C:/yourMail.eml");
var parser = new MimeParser();
var mg = parser.ToMailMessage(rawBytes);
//Save file
mg.Contents[0].SaveTo("C:/Temp/copyOfContent.png");
//Or save file to directory
mg.Contents[0].SaveToDirectory("C:/Temp/");
Apr 30, 2014 at 10:57 AM
Sorry I think you didn't understand my scenario... I have the email in my inbox and my mail also contains attachment so what my requirement is I want to download that full email along with attachment in an email.

I think the code which you have provided will read from the eml file i don't want that thing. I want to download my email which contains attachment as well.
May 1, 2014 at 8:59 AM
Will any 1 plz reply on this. ?
Coordinator
May 3, 2014 at 12:28 AM
Which protocol do you want to use? Pop3 or Imap?
Latest version Imap is some problem.
I'll check it Next Tuesday.

You can download your email.
Pop3Client cl = new Pop3Client("your server name");
cl.UserName = "your name";
cl.Password = "pass";
if (cl.Authenticate() ==  true)
{
    Int32 mailIndex = 1;
    MailMessage mg = cl.GetMessage(mailIndex);
}
See here.
https://higlabo.codeplex.com/documentation
May 5, 2014 at 11:11 AM
Thanks for your reply... Higty...

I am using Pop3 protocol for retrieving emails. Actually what my project manager asked me that can i download emails in eml file or msg file. So the attachment will be incorporated in the eml file or msg file.

I am trying my best to explain you well also tell me its best practice to store attachment in eml or msg file ?
May 9, 2014 at 4:25 PM
Hey Higty.. I still waiting for your reply on this.
Coordinator
May 9, 2014 at 4:58 PM
Edited May 9, 2014 at 5:13 PM
Hi. Sorry I missed you requirement.
I think you didn't understand my scenario... I have the email in my inbox and my mail also contains attachment so what my requirement is I want to download that full email along with attachment in an email.
I think that you may be able to achieve your requirement with this code.
MimeParser.Default.LoadMessageRawData = true;
MimeParser.Default.LoadContentRawData= true;

Pop3Client cl = new Pop3Client("your server name");
cl.UserName = "your name";
cl.Password = "pass";
if (cl.Authenticate() ==  true)
{
    Int32 mailIndex = 1;
    MailMessage mg = cl.GetMessage(mailIndex);
    var text = mg.GetRawText(); //.eml text
    File.WriteAllText("C:\YourMail.eml", text); //Save .eml file with attachment
}
Does it suit your requirement?