Created
November 9, 2015 11:29
-
-
Save doomzhou/3c1a66b79b40546dcaaa to your computer and use it in GitHub Desktop.
mutt 的python 模块,发送邮件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
32line ,消除了公司信息