How to read emails from gmail using C #

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

In fact, I want to read the correct email format, for example, from, topics, cups and bodies.

        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);
        }    

This is mistake. No connection can be made because the target machine has actively abandoned it.

+2
source share
4 answers

Try this, I added the port number along with the imap gmail server to connect 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);
    } 
+5
source

I am sure there are many libraries for this. A quick search showed this:

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

/, : http://www.codeproject.com/KB/gadgets/GadgetInterop.aspx

+1

, . API IMAP, .Net

, , google.

  • IMAP = > imap.google.com:993 (SSL)
  • SMTP = > smtp.google.com:587 (TLS)
0

Source: https://habr.com/ru/post/1763579/


All Articles