Author |
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 11 February 2017 at 9:52am | IP Logged
|
|
|
Hello Support,
I can load only "header" from an .eml file to disk?
Regards, Lello
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 12 February 2017 at 12:26am | IP Logged
|
|
|
How I can read only headers ?
Code:
byte[] msgBytes = null;
using (BinaryReader br = new BinaryReader(File.OpenRead(@"C:\Docs\TestMail.eml")))
{
msgBytes = br.ReadBytes(xxxx); //<-- How I can read only header?
}
MailMessage msg = new MailMessage();
msg.LoadMessage(msgBytes);
Console.WriteLine(msg.Subject);
|
|
|
Regards, Lello
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 12 February 2017 at 9:56am | IP Logged
|
|
|
For me this works.
Maybe there is a better way?
Code:
string msgString = "";
using (FileStream fs = new FileStream(file.FullName, FileMode.Open))
{
string sLine;
StreamReader sr = new StreamReader(fs);
while ((sLine = sr.ReadLine()) != null)
{
msgString += sLine + Environment.NewLine;
if (sLine == string.Empty)
{
//StartBody
break;
}
}
}
MailMessage msg = new MailMessage();
msg.LoadMessage(Encoding.ASCII.GetBytes(msgString));
|
|
|
Regards, Lello
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 13 February 2017 at 1:19am | IP Logged
|
|
|
Hi,
Just set msg.Parser.ParseHeaderOnly=true prior to calling msg.LoadMessage.
Regards,
Alex
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 13 February 2017 at 2:54am | IP Logged
|
|
|
|
Back to Top |
|
|