Subject: Loading mailmessage from a stream
Date: 2012-11-28 19:30:19
From: James Lawyer
Source: loading-mailmessage-stream
----------------------------------------------------------------------

I am trying to load RFC 822 messages. Each message has a single attachment, which is a RFC 822 message. I am able read in the RFC 822 message from the file system and save the RFC 822 attachment as a file. I can then load the saved RFC 822 message as a mailmessage without any problems.

But I want to skip the step of writing out the attachement to the file system and then reading it back in from the file system. When I write the 822 attachment to a stream, instead of the file system, and then try the "message load:(MailMessage mail1 = new MailMessage(jim);)" it fails with the following exception:

Unable to parse email message, headers end with an invalid line.

Any ideas on what the problem maybe?

Thanks.

[code lang='c#']

foreach (Attachment attachment in mail.Attachments)

{

string fn = Destination +"\\" + fileName.Name;

if (!fn.ToLower().EndsWith(".eml"))

{

fn = fn + ".eml";

}

//listBox1.Items.Add("Processing: " + fn + " " + attachment.MediaType);

int size = (int)attachment.GetContentLength();

Stream jim = new MemoryStream(size);

attachment.Save(jim);

MailMessage mail1 = new MailMessage(jim);

attachment.Save(jim);

//mail1.Save(fn, ComponentPro.Net.Mail.MailFormat.OutlookMsg);

}

//progressBar1.Increment(1);

return ;

}

catch (Exception exc)

{

// listBox1.Items.Add("An error occurred: " + exc.Message);

listBox1.Invoke((Action)delegate { Listbox1Update("An error occurred: " + exc.Message); });

}

return ;

}

[/code]i figure out the problem.

---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index