发送email给列表中的邮箱--python
来源:互联网 发布:linux rm -rf 作死 编辑:程序博客网 时间:2024/05/19 18:10
#!/usr/bin/python# -*- coding: utf-8 -*- #from email.Header import Headerfrom email.MIMEText import MIMETextfrom email.MIMEMultipart import MIMEMultipartimport smtplib, datetimeimport os,sysimport datetimeimport timeemail_code='utf-8'email_header='本周周报'server_port='25'main_msg=''list_file='send_list.dat'#当前日期#print datetime.date.today()#求指定日期前的datebegin_date=datetime.date.today()-datetime.timedelta(days=7)#格式化日期#print begin_date.strftime("%Y%m%d")#print time.strftime("%Y%m%d",time.localtime())file_path='/home/nantian/tmp/工作情况汇报_%s-%s.docx' %(begin_date.strftime("%Y%m%d"),\ time.strftime("%Y%m%d",time.localtime()))try: send_addr=sys.argv[1] send_passwd=sys.argv[2] server_addr='smtp.%s' % send_addr.split('@')[1]except IndexError,e: print "Usage:%s address password!" % sys.argv[0] quit()def send_email(rcv_text,rcv_addr,send_file): msg = MIMEMultipart() txt = MIMEText(rcv_text,'utf-8') msg.attach(txt) try: att = MIMEText(open(file_path, 'rb').read(), 'base64', email_code) msg["Accept-Language"]="zh-CN" msg["Accept-Charset"]='ISO-8859-1,"%s"' % email_code att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment;filename="%s"' % os.path.basename(file_path) msg.attach(att) except IOError,e: pass msg['to'] = rcv_addr msg['from'] = send_addr msg['subject'] = Header(email_header,email_code) server.sendmail(msg['from'], msg['to'],msg.as_string())server = smtplib.SMTP()server.connect(server_addr,server_port)try: server.login(send_addr, send_passwd) list_line=open(list_file,'rb')except smtplib.SMTPAuthenticationError,e: print "Error:Username or password error!" quit()except IOError: print "Eorro:Open file [%s] error!" % list_file quit()if not os.path.exists(file_path) : email_header='本周周报没有写!,或者文档名称不正确!' send_email("本周周报没写!","admin@qq.com","") quit()for eachline in list_line: addr=eachline.split("|")[0] main_msg=eachline.split("|")[1] if addr[0] == '#': continue send_email(main_msg,addr,file_path)server.close
因为工作中需要发送工作报告给领导,说不定那天玩游戏就忘记了。这样写一个工具加到crontab中,提醒自己。
之需要将文档放在指定目录下,脚本就会email。
ps:需要维护一个邮件列表。可以适当修改,将自己的用户密码加密保存。
- 发送email给列表中的邮箱--python
- python的smtplib发送email给多人要传列表而不是','.join(LIST)
- Python使用QQ邮箱发送多收件人email
- 使用QQ邮箱发送email(Python【支持中文】)
- Python发送邮件给qq邮箱
- python给qq邮箱发送邮件
- email 发送邮箱修改密码
- python 读取本地txt文档发送邮件给qq邮箱
- Python发送Email
- Python 发送Email
- python 发送Email程序
- python发送email
- python实现发送email
- Python 发送Email
- python 简单email发送
- 抓取文件中的email邮箱
- Java使用qq邮箱发送email
- 给QQ邮箱发送邮件
- Visual Basic 2005程序设计实例教程(奋斗的小鸟)_PDF 电子书
- Visual Basic 2005从入门到精通(奋斗的小鸟)_PDF 电子书
- Sublime 格式化代码 快捷键以及插件使用
- 安装TOMCAT+JAVA
- 第七周*思维游戏(项目4)上机制作2
- 发送email给列表中的邮箱--python
- 安装LVS+KEEPALIVED
- 一个PHP的远程图片抓取函数
- myeclipse web service 示例(java project 转 web service)
- Ultraedit 中文显示乱码
- Visual Basic 2008入门经典(第五版)(奋斗的小鸟)_PDF 电子书
- 第八周项目1-体验主动撞错
- extGrid里ComboBox显示下拉框的值
- Android init.rc (Android init language)