how to read email from gmail using c#

后端 未结 4 494
情深已故
情深已故 2020-12-21 13:15

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.

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 13:46

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

提交回复
热议问题