简体   繁体   中英

Outlook Email Template - Send Using Python

I am looking to send a saved email template to a user using Python.

This is my current Python function using Win32 library.

How can I adjust this to pick up the template and then send it?

def send_email(sender,recipient):
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = recipient
    mail.Subject = Subject_Req
    mail.HTMLBody = Content_Email
    mail.SentOnBehalfOfName = sender
    mail.GetInspector 
    mail.Send()

I am not able to find the corresponding property.

Use CreateItemFromTemplate.

https://docs.microsoft.com/en-us/office/vba/api/outlook.application.createitemfromtemplate

def send_email(sender,recipient):
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItemFromTemplate("pathToTemplate", )
    mail.To = recipient
    mail.Subject = Subject_Req
    mail.HTMLBody = Content_Email
    mail.SentOnBehalfOfName = sender
    mail.GetInspector 
    mail.Send()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM