Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

I want to load all inbox read and unread mail into my website gridview.
I already use the following code but it will display one year old emails
Pop3Client pop3Client;
            if (Session["Pop3Client"] == null)
            {
                pop3Client = new Pop3Client();
                pop3Client.Connect(txtMailServer.Text, int.Parse(txtPort.Text), chkSSL.Checked);
                //pop3Client.Authenticate(txtEmail.Text, txtPassword.Text);
                pop3Client.Authenticate(txtEmail.Text, txtPassword.Text, AuthenticationMethod.UsernameAndPassword);
                Session["Pop3Client"] = pop3Client;
            }
            else
            {
                pop3Client = (Pop3Client)Session["Pop3Client"];
            }
            int count = pop3Client.GetMessageCount();
            DataTable dtMessages = new DataTable();
            dtMessages.Columns.Add("MessageNumber");
            dtMessages.Columns.Add("From");
            dtMessages.Columns.Add("Subject");
            dtMessages.Columns.Add("DateSent");
            int counter = 0;
            for (int i = count; i >= 1; i--)
            {
                Message message = pop3Client.GetMessage(i);
                dtMessages.Rows.Add();
                dtMessages.Rows[dtMessages.Rows.Count - 1]["MessageNumber"] = i;
                dtMessages.Rows[dtMessages.Rows.Count - 1]["From"] = message.Headers.From.Address;
                dtMessages.Rows[dtMessages.Rows.Count - 1]["Subject"] = message.Headers.Subject;
                dtMessages.Rows[dtMessages.Rows.Count - 1]["DateSent"] = message.Headers.DateSent.ToLocalTime();
                counter++;
                if (counter > 20)
                {
                    break;
                }
            }
            gvEmails.DataSource = dtMessages;
            gvEmails.DataBind();

please inform to me if any one know
Posted
Updated 8-Aug-14 22:36pm
v2
Comments
Nirav Prabtani 9-Aug-14 2:48am    
What is an issue in it??
sbsmanian 9-Aug-14 7:06am    
load email current date wise descending order
[no name] 9-Aug-14 4:37am    
exactly! what is the problem
sbsmanian 9-Aug-14 7:06am    
load email current date wise descending order

1 solution

Order your messages correctly by message.Headers.DateSent before loading them into the gridview.
 
Share this answer
 
Comments
sbsmanian 9-Aug-14 6:59am    
yes I tried that also but it display same result before one year.
please inform how to read particular mail in new page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900