Open Jacobvu84 opened 3 years ago
from imap_tools import MailBox, AND
# get email bodies from INBOX
with MailBox(host).login(username, password, 'INBOX') as mailbox:
for msg in mailbox.fetch(AND(from_='jacob.vu@gmail.com')):
body = msg.text or msg.html
print(body)
for uid, message in messages:
# Every message is an object with the following keys
message.raw_email
print(message.keys())
# To check all available keys
import re
text = "This is your e-mail body. It contains a link to <a href='http//www.google.com'>click here</a>."
link_pattern = re.compile('href=\'(.*?)[^>]*')
search = link_pattern.search(text)
if search is not None:
print("Link found! -> " + search.group(0).replace("'","").replace("href=",""))
else:
print("No links were found.")