Click here to Skip to main content
14,601,060 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello all,

I am working on Web Application in which I have to configure gmail . I want to show all Inbox mail in Grid view with Subject in descending Order(date wise) . I tried many code but not found good which work.

Read Gmail Inbox Message in ASP.NET[^]


I used this one but Its only show only few emails and in Ascending Order(Datewise).
Please provide me good link which work fine for this.

Also Tell me which is good to use IMAP or POP3.
I have some other code but that works for yahoo not for gmail.

Thanks In Advance
Neetesh Agarwal
Updated 13-Mar-13 1:57am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Neetesh Agarwal 13-Mar-13 7:00am
I also given same link above thats showing only few emails
Rate this:
Please Sign up or sign in to vote.

Solution 2

Using IMAP insted of Pop3 Server:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;

namespace mail
    public partial class WebForm1 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)


        protected void Button1_Click(object sender, EventArgs e)

            Imap client = new Imap();
            // connect to server

            client.Connect("", 993, SslMode.Implicit);

            // authenticate
            client.Login("username", "password");

            // select folder

            int NoOfEmailsPerPage = 10;
            int totalEmails = client.CurrentFolder.TotalMessageCount;
            // get message list - envelope headers
            ImapMessageCollection messages = client.GetMessageList(ImapListFields.Envelope);

            // display info about each message
            foreach (ImapMessageInfo message in messages)
                TableCell noCell = new TableCell();
                noCell.CssClass = "emails-table-cell";

                noCell.Text = Convert.ToString(message.To);
                TableCell fromCell = new TableCell();
                fromCell.CssClass = "emails-table-cell";
                fromCell.Text = Convert.ToString(message.From);
                TableCell subjectCell = new TableCell();
                subjectCell.CssClass = "emails-table-cell";
                subjectCell.Style["width"] = "300px";
                subjectCell.Text = Convert.ToString(message.Subject);
                TableCell dateCell = new TableCell();
                dateCell.CssClass = "emails-table-cell";
                if (message.Date.OriginalTime != DateTime.MinValue)
                    dateCell.Text = message.Date.OriginalTime.ToString();
                TableRow emailRow = new TableRow();
                EmailsTable.Rows.AddAt(2 + 0, emailRow);
            int totalPages;
            int mod = totalEmails % NoOfEmailsPerPage;
            if (mod == 0)
                totalPages = totalEmails / NoOfEmailsPerPage;
                totalPages = ((totalEmails - mod) / NoOfEmailsPerPage) + 1;


Santhosh Kumar 21-Sep-13 5:34am
client.Connect("", 993, SslMode.Implicit); doesn't connects me to the server can any one clarify me. thanks in advance
ADK1204 30-May-14 20:55pm
Are you going through a proxy?
ADK1204 30-May-14 20:54pm
Where is the IMAP class defined?
What IMAP reference was used for Solution 2 ???
Please provide a working solution if possible with IMAP dlls
Member 10549175 24-Aug-14 12:39pm
where is imap reference
Member 11539268 19-Mar-15 13:28pm
can anyone help me in how to download my emails to the database in C# windows application? reply me at Thanks in advance
Member 11334914 10-Apr-15 6:30am
how to add reference in this code becouse imap is not give error of assembly and reference
Rate this:
Please Sign up or sign in to vote.

Solution 3

Afzaal Ahmad Zeeshan 26-Sep-15 6:11am
Too old thread and not an appropriate way to answer the question. What more does it contribute to the thread at all?

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100