Click here to Skip to main content
15,889,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to retrieve mail from G-Mail. At first i used POP but after some time it was not working fine. can somebody help me with a piece of code. I am using windows form c#.Thanks in advance.
Posted
Updated 18-Nov-13 2:07am
v4

Check below link for more info.

C#
/// <summary>
/// Example showing:
///  - how to fetch all messages from a POP3 server
/// </summary>
/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
/// <param name="username">Username of the user on the server</param>
/// <param name="password">Password of the user on the server</param>
/// <returns>All Messages on the POP3 server</returns>
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
    // The client disconnects from the server when being disposed
    using(Pop3Client client = new Pop3Client())
    {
        // Connect to the server
        client.Connect(hostname, port, useSsl);

        // Authenticate ourselves towards the server
        client.Authenticate(username, password);

        // Get the number of messages in the inbox
        int messageCount = client.GetMessageCount();

        // We want to download all messages
        List<Message> allMessages = new List<Message>(messageCount);

        // Messages are numbered in the interval: [1, messageCount]
        // Ergo: message numbers are 1-based.
        // Most servers give the latest message the highest number
        for (int i = messageCount; i > 0; i--)
        {
            allMessages.Add(client.GetMessage(i));
        }

        // Now return the fetched messages
        return allMessages;
    }
}



Download all email from server
 
Share this answer
 
v5
Comments
agent_kruger 18-Nov-13 7:50am    
can you provide me with "Imap" class & refrences that are needed to add
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
Sampath Lokuge 18-Nov-13 7:53am    
This is for the asp.net web forms.What's your app ?
agent_kruger 18-Nov-13 7:55am    
my app is windows form
Sampath Lokuge 18-Nov-13 8:05am    
I have updated. Plz check that.
agent_kruger 21-May-14 10:28am    
sir, can you provide me with a "download link" of a solved question or article about getting email s from G-Mail as none of the above solution works in my application (c# win. form)
 
Share this answer
 
Comments
agent_kruger 21-May-14 10:28am    
sir, can you provide me with a "download link" of a solved question or article about getting email s from G-Mail as none of the above solution works in my application (c# win. form)

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