Skip to content

Instantly share code, notes, and snippets.

@doomzhou
Created November 9, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doomzhou/3c1a66b79b40546dcaaa to your computer and use it in GitHub Desktop.
Save doomzhou/3c1a66b79b40546dcaaa to your computer and use it in GitHub Desktop.
mutt 的python 模块,发送邮件
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import smtplib
import sys
import re
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart('alternative')
data = sys.stdin.readlines()
k = 0
for i in data:
if re.search(r'User-Agent: M', i):
break
k += 1
bdata, adata = data[:k], data[k+1:]
print bdata
content = '\n'.join(adata)
for i in bdata:
if re.match(r'Date:(.*)', i):
msg['Date'] = re.match(r'Date:(.*)', i).group(1)
if re.match(r'Subject:(.*)', i):
msg['Subject'] = re.match(r'Subject:(.*)', i).group(1)
if re.match(r'To:(.*)', i):
msg['To'] = re.match(r'To:(.*)', i).group(1)
if re.match(r'Cc:(.*)', i):
msg['Cc'] = re.match(r'Cc:(.*)', i).group(1)
msg['From'] c.com'
toaddr = msg['To'].split(',') + msg['Cc'].split(',')
msg.attach(MIMEText(content, 'plain'))
s = smtplib.SMTP_SSL('smtp.exmail.qq.com', port=465)
s.login(msg['From'], 'xxxx')
s.sendmail(msg['From'], toaddr, msg.as_string())
s.quit()
@doomzhou
Copy link
Author

doomzhou commented Nov 9, 2015

32line ,消除了公司信息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment