Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import smtplib
- import mimetypes
- from email import encoders
- from email.message import Message
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- import sys, os, socket
- os.system('pbpaste > ~/.mailhelp.tmp && vim ~/.mailhelp.tmp')
- toList = """jun.xiong1981@gmail.com
- xiong@baeri.org
- lisagaoxuedi@gmail.com
- nemani911@gmail.com
- 282607595@qq.com"""
- footer = """
- ----
- Jun (Johnny) Xiong, Ph.D.
- NASA Ames Research Center / BAERI
- Moffett Blvd, Mountain View
- CA 94035, USA"""
- subject = raw_input("Subject:")
- recipients = toList.split('\n')
- for i, addr in enumerate(recipients):
- print i+1, addr
- idx = raw_input("Which(1-%d):" % len(recipients))
- emailfrom = "jun.xiong1981@gmail.com"
- emailto = recipients[int(idx)-1]
- ans = raw_input("[to:%s][%s](Y/n):" % (emailto, subject)) or 'Y'
- if ans.lower() == 'n':
- exit()
- parent, child = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
- pid = os.fork()
- if pid:
- child.close()
- parent.sendall('hello, i am parent')
- response = parent.recv(1024)
- parent.close()
- else:
- parent.close()
- child.sendall('hello, i am child')
- message = child.recv(1024)
- username = "jun.xiong1981"
- password = "jupyterMark@0808"
- msg = MIMEMultipart()
- msg["From"] = emailfrom
- msg["To"] = emailto
- msg["Subject"] = subject
- cont = open('/Users/jxiong1/.mailhelp.tmp').read() + footer
- msg.attach(MIMEText(cont, 'plain'))
- server = smtplib.SMTP("smtp.gmail.com:587")
- server.starttls()
- server.ehlo()
- server.login(username,password)
- server.sendmail(emailfrom, emailto, msg.as_string())
- server.quit()
- print 'Send to [%s:%s] successfully.' % (emailto, subject)
- child.close()
Add Comment
Please, Sign In to add comment