Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Attachment> GetAttachments() {
- string hostname = "pop.gmail.com";
- int port = 995;
- bool useSSL = true;
- string attachmentType = "application/pdf";
- string email = "myemail@gmail.com";
- string emailFrom = "someone@gmail.com";
- string password = TxtBoxPassword.Text;
- if (!string.IsNullOrWhiteSpace(password))
- {
- Pop3Client client = new Pop3Client();
- client.Connect(hostname, port, useSSL);
- client.Authenticate(email, password, AuthenticationMethod.UsernameAndPassword);
- List<Attachment> listAttachments = new List<Attachment>();
- int count = client.GetMessageCount();
- for (int i = count; i >= 1; i--)
- {
- Message message = client.GetMessage(i);
- if (message.Headers.From.MailAddress.Address == emailFrom)
- {
- List<MessagePart> attachments = message.FindAllAttachments();
- foreach (MessagePart attachment in attachments)
- {
- if (attachment.ContentType.MediaType == attachmentType)
- listAttachments.Add(new Attachment(attachment));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement