import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'To address'
mail.Subject = 'Message subject'
mail.Body = 'Message body'
mail.HTMLBody = '<h2>HTML Message body</h2>' #this field is optional
# To attach a file to the email (optional):
attachment = "Path to the attachment"
mail.Attachments.Add(attachment)
mail.Send()
但一開始找不到win32com , 有訊息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'win32com'
直接執行 pip install win32com , 出現error:
ERROR: Could not find a version that satisfies the requirement win32com (from versions: none)
ERROR: No matching distribution found for win32com
實際上應該執行 pip install pypiwin32 .
測試OK.
Ref:
1.Send Outlook Email Via Python?
https://stackoverflow.com/questions/6332577/send-outlook-email-via-python
2.Python操作Word(Win32com)
https://zhuanlan.zhihu.com/p/67543981
Ref:
1.Send Outlook Email Via Python?
https://stackoverflow.com/questions/6332577/send-outlook-email-via-python
2.Python操作Word(Win32com)
https://zhuanlan.zhihu.com/p/67543981
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。