2

I want to create window application through which i can read email from gmail.

Actually i want to read proper format of email like to,from,subject,cc and body.

        using (Imap imap = new Imap())
        {
            imap.ConnectSSL("mail.company.com");
            imap.Login("angel_y@company.com", "xyx***");

            imap.SelectInbox();
            List<long> uids = imap.SearchFlag(Flag.Unseen);
            foreach (long uid in uids)
            {
                string eml = imap.GetMessageByUID(uid);
                IMail message = new MailBuilder()
                    .CreateFromEml(eml);

                Console.WriteLine(message.Subject);
                Console.WriteLine(message.TextDataString);
            }
            imap.Close(true);
        }    

It is this error. No connection could be made because the target machine actively refused it

jiya gupta
  • 109
  • 1
  • 2
  • 8
  • 5
    That's nice. Now, what's you question? Something that can be answered with less then code for the whole application? – Oded Jun 23 '10 at 12:27
  • GMail also has an IMAP interface, which is more widely supported. – Sjoerd Jun 23 '10 at 12:29

4 Answers4

5

Try this I have added the Port number along with the gmail imap server for connection to the server

    using (Imap imap = new Imap())
    {
        imap.ConnectSSL("imap.gmail.com", 993);
        imap.Login("angel_y@company.com", "xyx***"); // MailID As Username and Password

        imap.SelectInbox();
        List<long> uids = imap.SearchFlag(Flag.Unseen);
        foreach (long uid in uids)
        {
            string eml = imap.GetMessageByUID(uid);
            IMail message = new MailBuilder()
                .CreateFromEml(eml);

            Console.WriteLine(message.Subject);
            Console.WriteLine(message.TextDataString);
        }
        imap.Close(true);
    } 
Akshara
  • 3,361
  • 9
  • 31
  • 29
1

I am sure there are many libraries to do this. A quick search turned this up:

http://code.msdn.microsoft.com/CSharpGmail

And here is a gadget / widget app that has some code to do this: http://www.codeproject.com/KB/gadgets/GadgetInterop.aspx

Mike Ohlsen
  • 1,900
  • 12
  • 21
0

You may need to make sure you are using the correct hostname and port number. Configuring these settings will depend on the IMAP API you are using for .Net

But the settings you want to use are listed on google's site.

  • IMAP => imap.google.com:993 (SSL)
  • SMTP => smtp.google.com:587 (TLS)
Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
-1

gmail offers access via its config page to pull down emails through POP3/IMAP. Here are a few such links I found off of Google that could be used for IMAP access.

http://www.codeproject.com/KB/IP/imaplibrary.aspx

Accessing Imap in C#

http://koolwired.com/solutions/solutions.aspx?id=30

Hopefully that helps!

Community
  • 1
  • 1
ThaKidd KG5ORD
  • 1,535
  • 3
  • 24
  • 38