发布时间:2019-09-08 09:14:59编辑:auto阅读(1947)
# -*- coding:utf-8 -*-
import win32com.client as win32
import warnings
import sys
reload(sys)
sys.setdefaultencoding('utf8')
warnings.filterwarnings('ignore')
def sendemail(sub,body):
outlook = win32.Dispatch('outlook.application')
receivers = ['xxxx@pingan.com.cn;xxxx@pingan.com.cn;xxxx@pingan.com.cn']
mail = outlook.CreateItem(0)
mail.To = receivers[0]
mail.Subject = sub.decode('utf-8')
mail.Body = body.decode('utf-8')
# 添加附件
# mail.Attachments.Add('D:\Users\xxx\Desktop\email.log')
mail.Send()
sendemail('xxx,xx','xxx')
如果报错:com_error: (-2147221008, '\xc9\xd0\xce\xb4\xb5\xf7\xd3\xc3 CoInitialize\xa1\xa3', None, None)
只需导入pythoncom包,import pythoncom
并在方法内加入pythoncom.CoInitialize()即可。
上一篇: Python基础知识点总结
下一篇: 【python 连接hbase】pyth
47608
45994
36911
34473
29085
25716
24569
19716
19248
17758
5568°
6158°
5694°
5738°
6710°
5485°
5488°
5992°
5965°
7298°