code_junkie

Recommendations for a .NET component to access an email inbox

Nov 10th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // create client, connect and log in
  2. Imap client = new Imap();
  3. client.Connect("imap.example.org");
  4. client.Login("username", "password");
  5.  
  6. // select folder
  7. client.SelectFolder("Inbox");
  8.  
  9. // get message list - envelope headers
  10. ImapMessageCollection messages = client.Search
  11. (
  12. ImapSearchParameter.HasFlagsNoneOf(ImapMessageFlags.Seen)
  13. );
  14.  
  15. // display info about each message
  16. Console.WriteLine("UID | From | To | Subject");
  17. foreach (ImapMessageInfo message in messages)
  18. {
  19. Console.WriteLine(
  20. "{0} | {1} | {2} | {3}",
  21. message.UniqueId,
  22. message.From,
  23. message.To,
  24. message.Subject);
  25. }
  26.  
  27. // disconnect
  28. client.Disconnect();
  29.  
  30. ImapMessageCollection messages = client.Search
  31. (
  32. ImapSearchParameter.Arrived(DateTime.Now.AddYears(-1), DateTime.Now),
  33. ImapSearchParameter.Size(1024 * 100, Int32.MaxValue)
  34. );
  35.  
  36. using(Imap imap = new Imap())
  37. {
  38. imap.Connect("imap.server.com");
  39. imap.Login("user", "password");
  40.  
  41. imap.SelectInbox();
  42. List<long> uidList = imap.SearchFlag(Flag.Unseen);
  43. foreach (long uid in uidList)
  44. {
  45. IMail mail = new MailBuilder()
  46. .CreateFromEml(imap.GetMessageByUID(uid));
  47. Console.WriteLine(mail.Subject);
  48. }
  49. imap.Close();
  50. }
Add Comment
Please, Sign In to add comment