python下(outlook)自动发邮件

前言:我的测试环境是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('[email protected]')
    mail_item.Subject = 'Mail Test'
 
    mail_item.BodyFormat = 2          # 2: Html format
    mail_item.HTMLBody  = '''
        

Hello, This is a test mail.

Hello Guys. '''
mail_item.Attachments.Add('path and file') mail_item.Send() if __name__ == '__main__': send_mail()

你可能感兴趣的:(Python)