Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import imaplib
  2. import email
  3. import smtplib
  4.  
  5. username =  '1b739fc7253a54687@gmail.com'
  6. password = 'a8798acc17766a'
  7.  
  8. imap_server = imaplib.IMAP4_SSL("imap.gmail.com", 993)
  9. imap_server.login(username, password)
  10.  
  11. server = smtplib.SMTP('smtp.gmail.com', 587)
  12. server.ehlo()
  13. server.starttls()
  14. server.ehlo()
  15. server.login(username, password)
  16.  
  17. imap_server.select('INBOX')
  18.  
  19. status, email_ids = imap_server.search(None, '(UNSEEN)')
  20. #print email_ids[0].split(' ')
  21.  
  22. recipient = ['kburkeorg@gmail.com']
  23.  
  24. for e in email_ids[0].split(' '):
  25.     if e is not '':
  26.         raw_msg = imap_server.fetch(e, '(RFC822)')
  27.         msg = email.message_from_string(raw_msg[1][0][1])
  28.  
  29.         #modify reply-to so we preserve email address
  30.         if not msg['Reply-To']:
  31.             msg['Reply-To'] = msg['From']
  32.         server.sendmail(msg['From'], recipient, msg.as_string())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement