Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET Objects

 AfterLogic Forum : MailBee.NET Objects
Subject Topic: I can load only header from file ? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 11 February 2017 at 9:52am | IP Logged Quote juris

Hello Support,

I can load only "header" from an .eml file to disk?

Regards, Lello

Back to Top View juris's Profile Search for other posts by juris
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 12 February 2017 at 12:26am | IP Logged Quote juris

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 View juris's Profile Search for other posts by juris
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 12 February 2017 at 9:56am | IP Logged Quote juris

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 View juris's Profile Search for other posts by juris
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 13 February 2017 at 1:19am | IP Logged Quote Alex

Hi,

Just set msg.Parser.ParseHeaderOnly=true prior to calling msg.LoadMessage.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 13 February 2017 at 2:54am | IP Logged Quote juris

Back to Top View juris's Profile Search for other posts by juris
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide