python发邮件脚本修改
下面是我在网上找到的python实现电子邮件发送脚本,现在需要对下面做一下修改,大家帮帮忙!感谢!修改说明:
假设该脚本名为sendmail.py
原来执行该脚本是./sendmail.py
现在要求执行该脚本是./sendmail.py 邮件正文(即 ./sendmail.py 后面 加上 将要发送的邮件的正文)
然后send_mail(u'这是python测试邮件',u'python发送邮件'),python发送邮件,这里替换为 邮件正文
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#导入smtplib和MIMEText
import smtplib,sys
from email.mime.text import MIMEText
def send_mail(sub,content):
#############
#要发给谁,这里发给1个人
mailto_list=["wunanhui_1@]
#####################
#设置服务器,用户名、口令以及邮箱的后缀
mail_host="smtp.
mail_user="wunanhui_1"
mail_pass="**********"
mail_postfix="
######################
'''''
to_list:发给谁
sub:主题
content:内容
send_mail("aaa@,"sub","content")
'''
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_charset='gbk')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(mailto_list)
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, mailto_list, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(u'这是python测试邮件',u'python发送邮件'):
print u'发送成功'
else:
print u'发送失败'