需求:根据不同业务员发送不同附件的邮件。直接调用outlook,不需密码。
要点:
1.不定的抄送人员和附件的添加,用list实现
2.cc中人员添加,注意“;”如果是直接加是不生效的。
import win32com.client as win32
import datetime
year=str(datetime.datetime.now().year)+"年"
month=str(datetime.datetime.now().month)+"月"
def send_email(subject, body, recipient,cc,attachments):
outlook = win32.Dispatch('Outlook.Application')
mail = outlook.CreateItem(0)
mail.Subject = subject
mail.Body = body
mail.To = recipient
mail.CC='; '.join(cc)
# for c in cc: 这种形式不可以,分号不会出现
# mail.CC+=c+';'
#print(mail.CC)
for attachment_path in attachments:
mail.Attachments.Add(attachment_path)
mail.Send()
send_email('催款通知-有账期应收款-'+month+'-杜工', '杜工:\n你好!\n附件是'+year+month+'应收款,请查收催款,谢谢!',
's@k',
['li@k','sa@k','san@k','si@k','q@k'],
[r'C:\Users\d\Desktop\pd脚本\Pudong Development Bank.png'])