######################################
## 作者: 心如海 724367502@qq.com ##
## 请勿改动下面代码 ##
## 2021-3-14 Shenzhen ##
######################################
import win32com.client as win32
import pythoncom
import xlrd
import calendar
import os
import openpyxl
import win32ui
pythoncom.CoInitialize()
def startoutlook():
try:
win32ui.FindWindow(None, "Microsoft Outlook")
except win32ui.error:
os.startfile("Outlook")
def send_mail(**kwargs):
#print(kwargs['p'])
manager=kwargs['p']['manager']
mail_to = kwargs['p']['mail_to']
mail_cc = kwargs['p']['mail_cc']
reply_date_cn = list(kwargs['p']['reply_date_cn'])[0]
reply_date_en = list(kwargs['p']['reply_date_en'])[0]
bl=kwargs['p']['bl']
default_term_cn = list(kwargs['p']['default_term_cn'])[0]
default_term_en = list(kwargs['p']['default_term_en'])[0]
print('使用模板:',bl)
# 邮件正文中的员工列表
table_rows=kwargs['p']['table_rows']
#邮件正文模板
email_template=kwargs['p']['email_template']
print('Mail to:',mail_to)
print('Mail cc:',mail_cc)
print('收件人:', manager)
outlook = win32.Dispatch('Outlook.Application')
reciList = mail_to
recipients_list =''
cc_list=''
mail_item = outlook.CreateItem(0) # 0: olMailItem
mail_item.GetInspector
#mail_item.Display(False)
orbody=mail_item.HTMLBody # 先读取outlook签名
for i in range(len(reciList)):
#recipients_list+="'"+reciList[i]+"'"+';'
#print(recipients_list)
mail_item.Recipients.Add(reciList[i])
for i in range(len(mail_cc)):
if len(mail_cc[i])>0:
cc_list+=mail_cc[i]+';'
#mail_item.Recipients.Add(recipients_list)
#
mail_item.CC=cc_list
mail_item.Subject = 'Contract Reveiw to '+ manager+' cut of '+ reply_date_en
print('Subject is :',mail_item.Subject)
mail_item.BodyFormat = 2 # 2: Html format
#读取bl 对应的邮件正文模板
try:
email_templates = open('./template/'+email_template, 'r', encoding='UTF-8') # open email template
print('读取模板。。。。成功!')
except Exception as e:
print('请检查模板是
用python写邮件和附件自动生成发送系统
最新推荐文章于 2024-06-18 16:46:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)