如何使用C#读取Gmail电子邮件 [英] how to read email from gmail using c#

查看:545
本文介绍了如何使用C#读取Gmail电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建窗口的应用程序,通过它我可以读取Gmail电子邮件。

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

推荐答案

试试这个我也一起加入端口号与用于连接到服务器

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

这篇关于如何使用C#读取Gmail电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆