From 38b4062b899fa9ab6c86f3fb313d1fa471da9d87 Mon Sep 17 00:00:00 2001 From: hyfc <3365132+hyfc@users.noreply.github.com> Date: Sat, 9 Jun 2018 23:03:54 +0800 Subject: initial commit with some handy email utilities --- utils/__init__.py | 0 utils/mail.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 utils/__init__.py create mode 100644 utils/mail.py (limited to 'utils') diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/mail.py b/utils/mail.py new file mode 100644 index 0000000..3dc346f --- /dev/null +++ b/utils/mail.py @@ -0,0 +1,48 @@ +import poplib + + +class MailInfo(object): + """ + Class for storing mail's metadata + """ + def __init__(self): + self.index = 0 + self.size = 0 + self.status = "" + self.data = "" + +class EmailClient(object): + def __init__(self, email_account, password): + self.email_account = email_account + self.password = password + self.server = self.connect(self) + + @staticmethod + def connect(self): + # parse the server's hostname from email account + pop3_server = 'pop.'+self.email_account.split('@')[-1] + + server = poplib.POP3_SSL(pop3_server) + + # display the welcome info received from server, + # indicating the connection is set up properly + print(server.getwelcome().decode('utf8')) + + # authenticating + server.user(self.email_account) + server.pass_(self.password) + + return server + + def get_mail_count(self): + _, mails, _ = self.server.list() + return len(mails) + + + +if __name__ == '__main__': + useraccount = "XXXXX" + password = "XXXXXX" + + client = EmailClient(useraccount, password) + client.get_mail_count() \ No newline at end of file -- cgit v1.2.3