File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 1- import datetime
2- import smtplib
1+ """
2+ What: Connect and get unread mail from imap example
3+ Author: James Campbell
4+ Date: 5 August 2019
5+ """
36import time
47import imaplib
58import email
69import sys
10+ import os
11+ import html2text
712# -------------------------------------------------
813#
914# Utility to read email from Gmail Using Python
1419FROM_PWD = sys .argv [1 ]
1520SMTP_SERVER = "imap.gmail.com"
1621SMTP_PORT = 993
17-
18- import email
19- import imaplib
20- import os
21- import html2text
22- import time
23- detach_dir = 'locationWhereYouWantToSaveYourAttachments'
22+ detach_dir = '~/Downloads'
2423
2524
2625def get_body (email_message ):
26+ """Get body of email message."""
2727 for payload in email_message .get_payload ():
2828 break
2929 return payload .get_payload ()
3030
3131
3232def two_way_email (server , uname , pwd ):
33+ """Fetch and read latest unseen messages."""
3334 username = uname
3435 password = pwd
36+ readonly = True
3537 mail = imaplib .IMAP4_SSL (server )
3638 mail .login (username , password )
37- mail .select ("inbox" )
39+ mail .select ("inbox" , readonly )
3840 try :
3941 result , data = mail .uid ('search' , None , '(UNSEEN)' )
4042 inbox_item_list = data [0 ].split ()
You can’t perform that action at this time.
0 commit comments