#!/usr/bin/python
# -*- coding: utf-8 -*-
#
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib, datetime
import os,sys
import datetime
import time email_code='utf-8'
email_header='本周周报'
server_port='25'
main_msg=''
list_file='send_list.dat' #当前日期
#print datetime.date.today() #求指定日期前的date
begin_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的更多相关文章

  1. c# 发送Email的2中方式

    先来第一种 // 版权所有 ZhuoYue Co.,Ltd 卓越一通秘密信息 // 文件名称:MyEmailByCDO.cs // 作 者:huangzh // 创建日期:2015-08-20 16: ...

  2. python 发送email

    pyton smtplib发送邮件 在邮件中设置并获取到 smtp域名 在脚本中执行命名,收件人可以是 多个,在列表中 import smtplib from email.mime.text impo ...

  3. [Python] 发送email的几种方式

    python发送email还是比較简单的,能够通过登录邮件服务来发送,linux下也能够使用调用sendmail命令来发送,还能够使用本地或者是远程的smtp服务来发送邮件,无论是单个,群发,还是抄送 ...

  4. Python Django中QQ邮箱授权码问题

    Python Django中QQ邮箱授权码问题 系统及软件版本如下: Ubuntu Kylin 16.04 Python 3.5.1 Django 1.9.7 PyCharm Community Ed ...

  5. Python 发送 email 的两种方式

    Python发送email的两种方式,分别为使用登录邮件服务器.调用sendmail命令来发送三种方法 Python发送email比较简单,可以通过登录邮件服务来发送,linux下也可以使用调用sen ...

  6. 使用python原生的方法实现发送email

    使用python原生的方法实现发送email import smtplib from email.mime.text import MIMEText from email.mime.multipart ...

  7. python之BIF函数在列表中的应用

    1 Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] on win32 2 T ...

  8. C#发送Email邮件(实例:QQ邮箱和Gmail邮箱)

    下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用: using System.Net.Mail; using System.Text; using System.Net; ...

  9. [转]C#发送Email邮件 (实例:QQ邮箱和Gmail邮箱)

    下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用:using System.Net.Mail;using System.Text;using System.Net; 程序 ...

随机推荐

  1. MAC下《暗黑世界》客户端版本编译说明!!

    原地址:http://blog.csdn.net/uxqclm/article/details/11970659 2013-09-24 12:02 161人阅读 评论(0) 收藏 举报   目录(?) ...

  2. 实用make最佳实践

    http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2288055.html 一.前言 Make工具最主要也是最基本的功能就是通过makefile文 ...

  3. java客户端连接MongoDB数据库的简单使用

    1.下载mongoDB的jar包,并引入到工程的CLASSPATH中下载:mongodb2.5驱动包下载 如果使用maven项目,最新的依赖如下: <dependency> <gro ...

  4. Where is the ActiveX Project Type for Delphi 10.1 Berlin

    n 10.1 Berlin the ActiveX project types are missing from the New Items Window under Delphi. They are ...

  5. 156. Binary Tree Upside Down

    题目: Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node ...

  6. SSO(转)

    一.介绍       主站下有多个子系统,每次登录主系统,跳转到子系统时,又需要重新登录: 子系统与主系统都有各自的用户信息表:各个系统的用户角色.权限也各不相同: 二.目的       每次登录主系 ...

  7. C++和java的区别

    Java区别于C++ 表面看来两者最大的不同在于Java没有指针,或者说,Java满地都是指针.对于编程者而言Java的这种设计是安全且更易用的.说Java满地是指针的原因在于它把指针的功能隐藏了,其 ...

  8. VC多文档编程技巧(取消一开始时打开的空白文档)

    VC多文档编程技巧(取消一开始时打开的空白文档) http://blog.csdn.net/crazyvoice/article/details/6185461 VC多文档编程技巧(取消一开始时打开的 ...

  9. VC C运行时库(CRTL)的几个版本及选用

    分类: Windows 2008-12-23 10:01 987人阅读 评论(0) 收藏 举报ciostreammfclibrary多线程import最近做项目碰到了一个关于在动态库中使用MFC以及在 ...

  10. exynos4412电路OrCAD问题

    图(1) K4B4G1646B,DDR3 图(2) JIA排针 问题:理论上,引脚命名不能重复,图(1)和图(2)都存在重复的引脚命名,但在进行DRC检查和网表输出时图(1)无任何问题,图(2)却有错 ...