def fetch(): """ Fetches some e-mail to test mailtools package 'mailFetcher' module :return: None """ # Fetch an e-mail fetcher = MailFetcherConsole() hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status) # load header for num, hdr in enumerate(hdrs[:2]): print(hdr) # if requested then e-mail. if input('load mail?') in ['y', 'Y']: print(fetcher.downloadMessage(num + 1).rstrip(), '\n', '-' * 70)
extrahdrs=[('X-Mailer', 'mailtools')], bodytext='Here is my source code\n', attaches=['selftest.py']) fetcher = MailFetcherConsole() def status(*args): print(args) hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status) for num, hdr in enumerate(hdrs): # print('header is:',hdr) if input('load mail?') in ['y', 'Y']: print(fetcher.downloadMessage(num + 1).rstrip(), '\n', '-' * 70) totalmail = len(hdrs) if totalmail < 5: last5 = 1 else: last5 = totalmail - 4 msgs, sizes, loadedall = fetcher.downloadAllMessages(status, loadfrom=last5) # for msg in msgs: # print(msg[:200], '\n', '-'*70) parser = MailParser() # print('\nparser messages, tottal messages is %d\n' % len(msgs)) for msg in msgs: fulltext = msg
sender = MailSenderAuthConsole() sender.sendMessage(From=mailconfig.myaddress, To=[mailconfig.myaddress], Subj='testing mailtools package', extrahdrs=[('X-Mailer', 'mailtools')], bodytext='Here is my source code\n', attaches=['selftest.py']) fetcher = MailFetcherConsole() def status(*args): print(args) hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status) for num, hdr in enumerate(hdrs[:5]): print(hdr) if input('load mail?') in ['Y', 'y']: print(fetcher.downloadMessage(num+1).rstrip(), '\n', '-'*70) last5 = len(hdrs) - 4 msgs, sizes, loadedall = fetcher.downloadAllMessages(status, loadfrom=last5) for msg in msgs: print(msg[:200], '\n', '-'*70) parser = MailParser() for i in [0]: fulltext = msgs[i] message = parser.parseMessage(fulltext) ctype, maintext = parser.findMainText(message) print('Parsed:', message['Subject']) print(maintext) input('Enter to exit')
# get these from __init__ from mailtools import MailFetcherConsole, MailSender, MailSenderAuthConsole if not mailconfig.smtpuser: sender = MailSender() else: sender = MailSenderAuthConsole() sender.sendMessage(From = mailconfig.myaddress, To = [mailconfig.myaddress], Subj = 'testing 123', extrahdrs = [('X-Mailer', 'mailtools')], bodytext = 'Here is my source code', attaches = ['selftest.py']) fetcher = MailFetcherConsole() def status(*args): print args hdrs, sizes, loadedall = fetcher.downloadAllHeaders(status) for num, hdr in enumerate(hdrs[:5]): print hdr if raw_input('load mail?') in ['y', 'Y']: print fetcher.downloadMessage(num+1), '\n', '-'*70 last5 = len(hdrs)-4 msgs, sizes, loadedall = fetcher.downloadAllMessages(status, loadfrom=last5) for msg in msgs: print msg[:200], '\n', '-'*70 raw_input('Press Enter to exit')