首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >netduino检查电子邮件

netduino检查电子邮件
EN

Stack Overflow用户
提问于 2012-12-28 12:03:24
回答 2查看 982关注 0票数 2

我看到了很多关于如何使用发送电子邮件的示例,但我希望运行一个检查电子邮件帐户的操作。

有没有人知道这是不是可以做到的(我相信可以),并给我举一些例子?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-31 00:01:17

我在网上找到了这段代码,但是"POP3_Client“没有被识别,我也看不到添加它的任何引用

代码语言:javascript
复制
 POP3_Client Mailbox = new POP3_Client(new >>>>IntegratedSocket<<<<<("pop.yourisp.com", 110), "yourusername", "yourpassword");
            Mailbox.Connect();
            Debug.Print("Message count: " + Mailbox.MessageCount.ToString());
            Debug.Print("Box size in bytes: " + Mailbox.BoxSize.ToString());

            uint[] Id, Size;
            Mailbox.ListMails(out Id, out Size);
            for (int Index = 0; Index < Id.Length; ++Index)
            {
                string[] Headers = Mailbox.FetchHeaders(Id[Index], new string[] { "subject", "from", "date" });
                Debug.Print("Mail ID " + Id[Index].ToString() + " is " + Size[Index].ToString() + " bytes");
                Debug.Print("Subject: " + Headers[0]);
                Debug.Print("From: " + Headers[1]);
                Debug.Print("Date: " + Headers[2]);
                Debug.Print("======================================================================");
            }

            Mailbox.Close();
票数 1
EN

Stack Overflow用户

发布于 2013-01-05 22:23:16

有几种方法可以让你获得gmail收件箱。

OpenPop

如果您只想使用POP,并且不介意使用外部库,这看起来是最好/最简单的方法。 OpenPop允许您访问安全/不安全的电子邮件帐户,并允许您选择端口。请参阅this post了解入门信息。

OpenPop是一个开源的C#.NET代码包,用于实现邮件获取和解析。在撰写本文时,它只使用微软的.NET框架库来完成所需的工作。但是对于访问安全的pop服务器,可以通过使用一些SSL库来扩展openPop。

例如,要通过Pop访问Gmail:

代码语言:javascript
复制
POPClient poppy = new POPClient();
poppy.Connect("pop.gmail.com", 995, true);
poppy.Authenticate(username@gmail.com, "password");
int Count = poppy.GetMessageCount();
if (Count > 0)
{
   for (int i = Count; i >= 1; i -= 1)
   {
     OpenPOP.MIMEParser.Message m = poppy.GetMessage(i, false);
     //use the parsed mail in variable 'm'
   }
}

TcpClient POP3:

要通过Pop3检索来自任何提供商的电子邮件,您可以使用TcpClient。与Gmail相比,这只是细微的不同,因为Gmail使用SSL和POP的995端口。这里有一个here的例子

代码语言:javascript
复制
// create an instance of TcpClient 

TcpClient tcpclient = new TcpClient();     

// HOST NAME POP SERVER and gmail uses port number 995 for POP 

tcpclient.Connect("pop.gmail.com", 995); 

// This is Secure Stream // opened the connection between client and POP Server

System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());

// authenticate as client  

 sslstream.AuthenticateAsClient("pop.gmail.com");

Gmail Atom Feed:

第一种方法是使用C# .Net Gmail Tools的一部分GmailAtomFeed。网站上写道:

GmailAtomFeed类提供了一个简单的对象层,用于以编程方式访问gmails提要。只需几行代码,就可以从gmail中检索并解析提要。之后,可以通过对象层AtomFeedEntryCollection访问这些条目,还可以访问原始提要和提要XmlDocument。

这是一个如何使用它的示例:

代码语言:javascript
复制
   // Create the object and get the feed 
   RC.Gmail.GmailAtomFeed gmailFeed = new RC.Gmail.GmailAtomFeed("username", "password"); 
   gmailFeed.GetFeed(); 

   // Access the feeds XmlDocument 
   XmlDocument myXml = gmailFeed.FeedXml 

   // Access the raw feed as a string 
   string feedString = gmailFeed.RawFeed 

   // Access the feed through the object 
   string feedTitle = gmailFeed.Title; 
   string feedTagline = gmailFeed.Message; 
   DateTime feedModified = gmailFeed.Modified; 

   //Get the entries 
   for(int i = 0; i &lt; gmailFeed.FeedEntries.Count; i++) { 
      entryAuthorName = gmailFeed.FeedEntries[i].FromName; 
      entryAuthorEmail = gmailFeed.FeedEntries[i].FromEmail; 
      entryTitle = gmailFeed.FeedEntries[i].Subject; 
      entrySummary = gmailFeed.FeedEntries[i].Summary; 
      entryIssuedDate = gmailFeed.FeedEntries[i].Received; 
      entryId = gmailFeed.FeedEntries[i].Id; 
   }

IMAP

如果您不局限于POP,另一种方法是使用IMAP。使用IMAP,您可以连接到SSL服务器并选择端口:

代码语言:javascript
复制
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);
} 
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14064416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档