Downloading multiple attachments using imaplib

For any future python travellers. Here is a class that downloads any attachment found for an email and saves it to a specific location. import email import imaplib import os class FetchEmail(): connection = None error = None def __init__(self, mail_server, username, password): self.connection = imaplib.IMAP4_SSL(mail_server) self.connection.login(username, password) self.connection.select(readonly=False) # so we can mark mails … Read more

Reading emails from Gmail in C#

Using the library from: https://github.com/pmengal/MailSystem.NET Here is my complete code sample: Email Repository using System.Collections.Generic; using System.Linq; using ActiveUp.Net.Mail; namespace GmailReadImapEmail { public class MailRepository { private Imap4Client client; public MailRepository(string mailServer, int port, bool ssl, string login, string password) { if (ssl) Client.ConnectSsl(mailServer, port); else Client.Connect(mailServer, port); Client.Login(login, password); } public IEnumerable<Message> GetAllMails(string mailBox) … Read more

Delete Email on Server using javax.mail

You should be able to do this via the standard APIs. First you need to get a reference to the Message (or messages) you want to delete – if you’re successfully reading them then you’re already able to do this. Now, there’s no explicit delete() operation, but you can mark a message as deleted like … Read more

How to get the list of available folders in a mail account using JavaMail

Sergey is close, but by default JavaMail’s list() does a LIST “” %, which gives you only top-level folders. GMail puts its system folders (All Mail, Drafts, Sent Mail, Spam, Starred, and Trash) under the non-selectable folder [Gmail], so you really need to do a LIST “” * instead. Otherwise, you’ll just get back INBOX, … Read more