Receive replies from Gmail with smtplib - Python -


ok, working on type of system can start operations on computer sms messages. can send initial message:

import smtplib    fromadd = 'gmailfrom'   toadd  = 'smsto'   msg = 'options \nh - \nt - terminal'    username = 'gmail'   password = 'pass'    server = smtplib.smtp('smtp.gmail.com:587')   server.starttls()   server.login(username , password)   server.sendmail(fromadd , toadd , msg)   server.quit() 

i need know how wait reply or pull reply gmail itself, store in variable later functions.

instead of smtp used sending emails, should use either pop3 or imap (the latter preferable). example of using smtp (the code not mine, see url below more info):

import imaplib mail = imaplib.imap4_ssl('imap.gmail.com') mail.login('myusername@gmail.com', 'mypassword') mail.list() # out: list of "folders" aka labels in gmail. mail.select("inbox") # connect inbox.  result, data = mail.search(none, "all")  ids = data[0] # data list. id_list = ids.split() # ids space separated string latest_email_id = id_list[-1] # latest  result, data = mail.fetch(latest_email_id, "(rfc822)") # fetch email body (rfc822) given id  raw_email = data[0][1] # here's body, raw text of whole email # including headers , alternate payloads 

shamelessly stolen here


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -