前言:我的测试环境是python3.68; 当你打开outlook; 通过以下代码可以自动发邮件
import win32com.client as win32
def send_mail():
outlook = win32.Dispatch('Outlook.Application')
mail_item = outlook.CreateItem(0) # 0: creat mail
mail_item.Recipients.Add('xx@qq.com')
mail_item.Subject = 'Mail Test'
mail_item.BodyFormat = 2 # 2: Html format
mail_item.HTMLBody = '''
<H2>Hello, This is a test mail.</H2>
Hello Guys.
'''
mail_item.Attachments.Add('path and file')
mail_item.Send()
if __name__ == '__main__':
send_mail()