Advertisement
Guest User

Untitled

a guest
Jul 8th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public List<Attachment> GetAttachments() {
  2. string hostname = "pop.gmail.com";
  3. int port = 995;
  4. bool useSSL = true;
  5. string attachmentType = "application/pdf";
  6.  
  7. string email = "myemail@gmail.com";
  8. string emailFrom = "someone@gmail.com";
  9. string password = TxtBoxPassword.Text;
  10.  
  11. if (!string.IsNullOrWhiteSpace(password))
  12. {
  13. Pop3Client client = new Pop3Client();
  14. client.Connect(hostname, port, useSSL);
  15. client.Authenticate(email, password, AuthenticationMethod.UsernameAndPassword);
  16.  
  17. List<Attachment> listAttachments = new List<Attachment>();
  18.  
  19. int count = client.GetMessageCount();
  20. for (int i = count; i >= 1; i--)
  21. {
  22. Message message = client.GetMessage(i);
  23. if (message.Headers.From.MailAddress.Address == emailFrom)
  24. {
  25. List<MessagePart> attachments = message.FindAllAttachments();
  26. foreach (MessagePart attachment in attachments)
  27. {
  28. if (attachment.ContentType.MediaType == attachmentType)
  29. listAttachments.Add(new Attachment(attachment));
  30. }
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement