def get_mails(self): from .models import Letter, Attachment try: with open('mail_app/mail_data.json', 'rb') as data_file: downloaded_summary = pickle.load(data_file) mail_data_exists = True except FileNotFoundError: downloaded_summary = None mail_data_exists = False self.latest_letters = ezgmail.search('in=inbox') for letter in self.latest_letters: letter = letter.messages[0] if ezgmail.summary(letter, printInfo=False ) == downloaded_summary and mail_data_exists: break else: aware_datetime = make_aware(letter.timestamp) letter_obj = Letter(mailer=letter.sender, topic=letter.subject, text=letter.body, date_time=aware_datetime) letter_obj.save() for file in letter.attachments: letter.downloadAttachment( file, downloadFolder='media/mail_attachments/') attachment = Attachment() attachment.file.name = 'media/mail_attachments/' + file attachment.letter = letter_obj attachment.save() with open('mail_app/mail_data.json', 'wb') as data_file: latest_letter_summary = ezgmail.summary(self.latest_letters[0], printInfo=False) pickle.dump(latest_letter_summary, data_file)
def respose(choice): if choice == '1': print("enter recipient:- ") recipient = input() subject = input("Enter subject:-") text = input("Enter your message(should be 1 liner):- ") #for i in range(0,len(recipients)): # recipient=str(recipients[i]) ezgmail.send(recipient, subject, text) if choice == '2': unread = ezgmail.unread() #get subject and date results = ezgmail.summary(unread) #print the email print(str(unread[0].messages[0])) if choice == '3': #searching gSearch = input("what you want to search:-") search_result = ezgmail.search(gSearch) print(len(search_result)) results = ezgmail.summary(search_result) if choice == '4': #downloadinng gSearch = input("what you want to search:-") attacmentName = input("name of the attachment:-") download = ezgmail.search(gSearch) download[0].messages[0].downloadAttachment(attacmentName) if choice == '5': exit()
def test_basic(): assert ezgmail.EMAIL_ADDRESS == TEST_EMAIL_ADDRESS attachmentFilename = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'attachment.txt') # This test doesn't check the results, it just makes sure these functions don't raise any exceptions: ezgmail.send(TEST_EMAIL_ADDRESS, TEST_SUBJECT, 'This is the body of the email.', [attachmentFilename]) unreadThreads = ezgmail.unread() unreadThreads[ 0] # NOTE: Make sure the test email account always has at least one unread message. ezgmail.summary(unreadThreads, printInfo=False) recentThreads = ezgmail.recent() msg = recentThreads[0].messages[0] msg.sender msg.recipient msg.subject msg.body msg.timestamp ezgmail.search('mancala')
import ezgmail #Checks work email for unread emails unreadThreads = ezgmail.unread() ezgmail.summary(unreadThreads) # Reads number of unread threads print('You have ' + str(len(unreadThreads)) + ' unread thread(s) in your work email') # Prints first unread email with all contents print(str(unreadThreads[0].messages[0])) # Prints subject of first unread email print(unreadThreads[0].messages[0].subject) # Prints body of first unread email print(unreadThreads[0].messages[0].body) print(unreadThreads[0].messages[0].timestamp) print(unreadThreads[0].messages[0].sender) print(unreadThreads[0].messages[0].recipient) ezgmail.send( '*****@*****.**', 'You have ' + str(len(unreadThreads)) + ' unread thread(s) in your work email', 'Please read your unread threads from ' + unreadThreads[0].messages[0].sender)
#Search import ezgmail resultThreads = ezgmail.search('RoboCop') len(resultThreads) ezgmail.summary(resultThreads) #Download import ezgmail threads = ezgmail.search('vacation photos') threads[0].messages[0].attachments threads[0].messages[0].downloadAttachment('tulips.jpg') threads[0].messages[0].downloadAllAttachments(downloadFolder='vacation2019')
import ezgmail import os UnreadThreads = ezgmail.unread() ezgmail.summary("unreadThreads") ezgmail.init() ezgmail.EMAIL_ADDRESS('*****@*****.**') os.chdir('/Users/ezrahampton/PycharmProjects/untitled') ezgmail.send('*****@*****.**', 'python scripting', "Hello all and welcome to the new age of tech and such", cc='*****@*****.**', bcc='[email protected],')
# 인증된 이메일 주소 출력 print(f"내 이메일 주소: {ezgmail.EMAIL_ADDRESS}") # 메일 보내기 ezgmail.send( recipient="*****@*****.**", # 받는이 subject="Subject line", # 주제문 body="Body of the email", # 본문 attachments=["attachment.txt"], # 첨부 파일들 cc=None, # 참조 bcc=None, # 비밀참조 ) # 읽지 않은 메일 확인하기 unread_threads = ezgmail.unread() # GmailThread 객체 리스트 반환 ezgmail.summary(unread_threads) # 메일 속성 접근하기 print(f"안 읽은 메일 갯수: {len(unread_threads)}") unread = unread_threads[0] print(f"GmailThread 문자열 값: {unread}") print(f"안 읽은 첫 번째 메일의 메시지 갯수: {len(unread.messages)}") print(f" 메시지 주제문: {unread.messages[0].subject}") print(f" 메시지 본문: {unread.messages[0].body}") print(f" 메시지 시간: {unread.messages[0].timestamp}") print(f" 메시지 보낸이: {unread.messages[0].sender}") print(f" 메시지 받는이: {unread.messages[0].recipient}") # 최근 받은 메일 확인 (기본 25) recent_threads = ezgmail.recent(maxResults=100) print(f"최근 받은 메일 갯수: {len(recent_threads)}")
import ezgmail resultThreads = ezgmail.search('RoboCop') print(len(resultThreads)) print(ezgmail.summary(resultThreads))
def __init__(self): unreadThreads = ezgmail.unread() # Collects unread email into lsit print("You have {} new emails".format(len(unreadThreads))) ezgmail.summary( unreadThreads ) # Command that provides name, subject line, and body of unread emails
### Carrega emojis OK = emoji.emojize(':heavy_check_mark:', use_aliases=True) NOK = emoji.emojize(':cross_mark:', use_aliases=True) ### Ids do Telegram botID = '784006906:AAF1qZj6fA9HdfdTijq04rmJ8nb5O43bmUg' channelID = '@datasciencetork' ### variaveis indir = '/home/ubuntu/scripts/load-dados-bmf/' bot = telepot.Bot(botID) print('Listening e-mail...') while (1): threads = ezgmail.unread() ### verifica e-mails marcados como não lidos for thread in threads: summary = ezgmail.summary(thread) sumary = ezgmail.summary(thread, printInfo=False) if '*****@*****.**' in sumary[0][0][0]: ### verifica se e-mail recebido é da B3 datetime = str(sumary[0][2]) bot.sendMessage(channelID,'Novo e-mail recebido da B3 às {} '.format(datetime) + OK) attachment = thread.messages[0].attachments[0] ### pega o nome do anexo thread.messages[0].downloadAttachment(attachment, indir) call('python '+indir+'parseResult.py',shell=True) call('python '+indir+'new_writeExcel.py',shell=True) call('python '+indir+'sendEmail.py',shell=True) exit(0) sleep(60)
import ezgmail unreadThreads = ezgmail.unread() # List of GmailThread objects. print(ezgmail.summary(unreadThreads)) print(len(unreadThreads)) print(str(unreadThreads[0])) print(len(unreadThreads[0].messages)) print(str(unreadThreads[0].messages[0])) print(unreadThreads[0].messages[0].subject) print(unreadThreads[0].messages[0].body) print(unreadThreads[0].messages[0].timestamp) print(unreadThreads[0].messages[0].sender) print(unreadThreads[0].messages[0].recipient) recentThreads = ezgmail.recent() # default: 25 print(len(recentThreads)) recentThreads = ezgmail.recent(maxResults=100) print(len(recentThreads))
import ezgmail #https://developers.google.com/gmail/api/quickstart/python unread = ezgmail.unread() summaries = ezgmail.summary(unread) print(unread[0].messages[0].body) #print(summaries)
#create repository if not os.path.isdir(main_repo): os.makedirs(main_repo) os.chdir(main_repo) if not os.path.isdir(main_repo + "/" + today): os.makedirs(main_repo + "/" + today) #navigate to emails #addres: [email protected] #password: dickbutt2 os.chdir(project_location) ezgmail.init() print('Access Granted, reading emails:', '\r\n', '\r\n') #parse emails/download attachments threads = ezgmail.search('heyyy') #print(threads[0]) ezgmail.summary(threads) print(threads[0].messages[0].attachments) threads[0].messages[0].downloadAllAttachments(downloadFolder=main_repo + '/' + today) #['tulips.jpg', 'canal.jpg', 'bicycles.jpg'] #threads[0].messages[0].downloadAttachment('tulips.jpg') #threads[0].messages[0].downloadAllAttachments(downloadFolder='vacation2019')
def le_email(): unreadThreads = ezgmail.unread( maxResults=30) # List of GmailThread objects. ezgmail.summary(unreadThreads)