在Windows应用程序中从imap.gmail.com获取电子邮件的C#代码 [英] C# code to fetch emails from imap.gmail.com in windows Application
本文介绍了在Windows应用程序中从imap.gmail.com获取电子邮件的C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要知道从imap.gmail.com获取电子邮件的基础C#逻辑
请不要给我任何库,我需要构建我自己的代码。
我认为这应该使用TCP监听器来实现。但我不知道实现这个的整个故事。
请指导。
Hi all,
I need to know the basis C# logic to fetch emails from imap.gmail.com
Please do not give me any library, i need to build my own code.
I think this should be implemented using TCP listener. but i donot know the whole story to implement this.
Please guide.
推荐答案
这是一个使用 AE.Net.Mail [ ^ ]:
Here''s a sample using AE.Net.Mail[^]:
// Connect to the IMAP server. The 'true' parameter specifies to use SSL
// which is important (for Gmail at least)
ImapClient ic = new ImapClient("imap.gmail.com", "name@gmail.com", "pass",
ImapClient.AuthMethods.Login, 993, true);
// Select a mailbox. Case-insensitive
ic.SelectMailbox("INBOX");
Console.WriteLine(ic.GetMessageCount());
// Get the first *11* messages. 0 is the first message;
// and it also includes the 10th message, which is really the eleventh ;)
// MailMessage represents, well, a message in your mailbox
MailMessage[] mm = ic.GetMessages(0, 10);
foreach (MailMessage m in mm)
{
Console.WriteLine(m.Subject);
}
// Probably wiser to use a using statement
ic.Dispose();
干杯,
Edo
Cheers,
Edo
这篇关于在Windows应用程序中从imap.gmail.com获取电子邮件的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文