Guest User

Untitled

a guest
Mar 12th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #! /usr/bin/python
  2. import smtplib
  3. import mimetypes
  4. from email import encoders
  5. from email.message import Message
  6. from email.mime.multipart import MIMEMultipart
  7. from email.mime.text import MIMEText
  8.  
  9. import sys, os, socket
  10.  
  11. os.system('pbpaste > ~/.mailhelp.tmp && vim ~/.mailhelp.tmp')
  12. toList = """jun.xiong1981@gmail.com
  13. xiong@baeri.org
  14. lisagaoxuedi@gmail.com
  15. nemani911@gmail.com
  16. 282607595@qq.com"""
  17.  
  18. footer = """
  19. ----
  20. Jun (Johnny) Xiong, Ph.D.
  21. NASA Ames Research Center / BAERI
  22. Moffett Blvd, Mountain View
  23. CA 94035, USA"""
  24.  
  25. subject = raw_input("Subject:")
  26. recipients = toList.split('\n')
  27. for i, addr in enumerate(recipients):
  28. print i+1, addr
  29. idx = raw_input("Which(1-%d):" % len(recipients))
  30. emailfrom = "jun.xiong1981@gmail.com"
  31. emailto = recipients[int(idx)-1]
  32.  
  33. ans = raw_input("[to:%s][%s](Y/n):" % (emailto, subject)) or 'Y'
  34. if ans.lower() == 'n':
  35. exit()
  36.  
  37. parent, child = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
  38. pid = os.fork()
  39.  
  40. if pid:
  41. child.close()
  42. parent.sendall('hello, i am parent')
  43. response = parent.recv(1024)
  44. parent.close()
  45. else:
  46. parent.close()
  47. child.sendall('hello, i am child')
  48. message = child.recv(1024)
  49.  
  50. username = "jun.xiong1981"
  51. password = "jupyterMark@0808"
  52. msg = MIMEMultipart()
  53. msg["From"] = emailfrom
  54. msg["To"] = emailto
  55. msg["Subject"] = subject
  56.  
  57. cont = open('/Users/jxiong1/.mailhelp.tmp').read() + footer
  58. msg.attach(MIMEText(cont, 'plain'))
  59. server = smtplib.SMTP("smtp.gmail.com:587")
  60. server.starttls()
  61. server.ehlo()
  62. server.login(username,password)
  63. server.sendmail(emailfrom, emailto, msg.as_string())
  64. server.quit()
  65. print 'Send to [%s:%s] successfully.' % (emailto, subject)
  66. child.close()
Add Comment
Please, Sign In to add comment