Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to unread mail from gmail accout created in google app.i try to read the mail.connection is established but email it is should 0.

C#
MailServer oServer = new MailServer("pop.gmail.com", "alpha@convate.com", "Siddhu@1", ServerProtocol.Pop3);
MailClient oClient = new MailClient("TryIt");

// Set SSL connection,
oServer.SSLConnection = true;

// Set 993 IMAP4 port
oServer.Port = 995;

try
{
    oClient.Connect(oServer);
    MailInfo[] infos = oClient.GetMailInfos();
 MessageBox.Show(infos.Length.ToString()); 

    for (int i = 0; i < infos.Length; i++)
    {
        MailInfo info = infos[i];
        Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
        info.Index, info.Size, info.UIDL);

        // Download email from GMail IMAP4 server
        Mail oMail = oClient.GetMail(info);
        MessageBox.Show("From" + oMail.From.ToString());
        MessageBox.Show("Subject" + oMail.Subject);
        MessageBox.Show("body" + oMail.TextBody);
        oClient.Delete(info);
    }

    // Quit and pure emails marked as deleted from Gmail IMAP4 server.
    oClient.Quit();
}
catch (Exception ep)
{
    MessageBox.Show(ep.Message);
}
Posted
v4

Refer - C# - Retrieve Email from Gmail Account[^].
Quote:
Because Gmail POP3 server doesn't work like normal POP3 server, it hides old emails automatically even the email was not deleted, so we suggest that you use IMAP4 protocol.
Please go through the code example and use Gmail IMAP4 server.
 
Share this answer
 
Comments
kalisiddayya 19-Aug-13 8:34am    
i cannot connect to imap .it is giving me an error that connection attempt failed beacause connection party did not response properly after a period of time
Did you enable IMAP service in Gmail settings?
kalisiddayya 19-Aug-13 8:40am    
i can enable in my account.i have to enable in the administrator gmail account also.
kalisiddayya 19-Aug-13 8:45am    
i enable in my gmail account .still i am getting this error
Check your Firewall and Antivirus. They may be blocking the connection.
Firewall and Antivirus software should be disabled or configured correctly.
/*HOW TO GET Just the UNREAD EMAILS*/

MailClient oClient = new MailClient("TryIt");

oClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.NewOnly;
 
Share this answer
 

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