Get Email Head

Oct 1, 2010 at 4:21 PM

Hi,
I'm trying to read the email head. I tried using different 2 syntax:

        Pop3Client pop = new Pop3Client("my@mail.com", "mypass", "mail.myserver.com");
        pop.Port = 110;
        pop.AuthenticateMode = Pop3AuthenticateMode.Pop;

        pop.Authenticate();

        if (pop.State == Pop3ConnectionState.Authenticated)
        {
            long totalMsgs = pop.GetTotalMessageCount();

            for (long i = 2; i <= totalMsgs; i++)
            {
                Pop3Message msg = pop.GetMessage(i);
                Response.Write("Header; " + msg.Header + "<br/>");           
            }

            pop.Close();
        }

I get this: System.Collections.Generic.List`1[Higuchi.Net.InternetTextMessage+Field]

The second case is:

    var MessageList = pop.ExecuteList();
    
    foreach (var email in MessageList )
    {
        var Head = pop.ExecuteTop(MessageList .MailIndex, 1); 
        Response.Write(Head.Header.ToString());
}
I get same string: System.Collections.Generic.List`1[Higuchi.Net.InternetTextMessage+Field]


Can you tell me where I made the bugs?
Cheeeeers

Coordinator
Oct 2, 2010 at 6:35 AM

Hi

Pop3Client cl = new Pop3Client("yourusername", "pass", "pop3.mailserver.com");
//Other settings...
cl.Authenticate();

StringBuilder sb = new StringBuider(1024);
for (int i = 0; i< totalCount; i++)
{
    Pop3Message mg = cl.GetMessage(i);
    sb.Length = 0;
    foreach(var header in mg)
   {
        sb.Append(header.Key + ": " + header.Value);
   }
   //Write something by sb object. 
}


And just now,I add HeaderData property to Pop3Message class!!
You can get entire header data by this property,

String headerText = mg.HeaderData;

I hope this meet your requirement.

regard.

Oct 2, 2010 at 4:03 PM

Hi higty,
thank you very much for helping me. I'm trying your c# sintax, like this:

 

        Pop3Client pop = new Pop3Client("mymail@mydomain.com", "mypass", "mail.mydomain.com");
        pop.Port = 110;
        pop.AuthenticateMode = Pop3AuthenticateMode.Pop;

        pop.Authenticate();

        long totalCount = pop.GetTotalMessageCount(); 

        StringBuilder sb = new StringBuilder(1024);

        for (int i = 0; i < totalCount; i++)
        {
            Pop3Message mg = pop.GetMessage(i);
            sb.Length = 0;

            foreach (var header in mg)
            {
                sb.Append(header.Key + ": " + header.Value);
            }
            //Write something by sb object. 
        }

but i get this error on line "foreach(var header in mg)"
foreach statement cannot operate on variables of type 'Higuchi.Net.Pop3.Pop3Message' because 'Higuchi.Net.Pop3.Pop3Message' does not contain a public definition for 'GetEnumerator'

Why does this happen
Thank you Again!

Coordinator
Oct 3, 2010 at 12:22 AM

Sorry, change code like this.
 
foreach (var header in mg.Header)
{
                sb.Append(header.Key + ": " + header.Value);
}