码迷,mamicode.com
首页 > 编程语言 > 详细

Python 调用outlook发送邮件(转 )

时间:2019-08-08 09:14:37      阅读:783      评论:0      收藏:0      [点我收藏+]

标签:==   not   send   splay   spl   www   pie   obj   __name__   

单账号:

import win32com.client as win32

def send_mail():
    outlook = win32.Dispatch(‘Outlook.Application‘)

    mail_item = outlook.CreateItem(0) # 0: olMailItem

    mail_item.Recipients.Add(‘wang.jinweis@fokker.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.Send()

if __name__ == ‘__main__‘:
    send_mail()

  

 

多账号:

def send_mail():
    outlook_app = win32.Dispatch(‘Outlook.Application‘)

    # choose sender account
    send_account = None
    for account in outlook_app.Session.Accounts:
        if account.DisplayName == ‘sender@hotmail.com‘:
            send_account = account
            break

    mail_item = outlook_app.CreateItem(0)   # 0: olMailItem

    # mail_item.SendUsingAccount = send_account not working
    # the following statement performs the function instead
    mail_item._oleobj_.Invoke(*(64209, 0, 8, 0, send_account))

    mail_item.Recipients.Add(‘receipient@qq.com‘)
    mail_item.Subject = ‘Test sending using particular account‘
    mail_item.BodyFormat = 2   # 2: Html format
    mail_item.HTMLBody = ‘‘‘
        <H2>Hello, This is a test mail.</H2>
        Hello Guys. 
        ‘‘‘

    mail_item.Send()


if __name__ == ‘__main__‘:
    send_mail()  

详细参见原文https://www.jianshu.com/p/4f0ed762f521 

 

Python 调用outlook发送邮件(转 )

标签:==   not   send   splay   spl   www   pie   obj   __name__   

原文地址:https://www.cnblogs.com/luoye00/p/11319107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!