简体   繁体   English

使用 python 发送 Outlook 电子邮件

[英]Send outlook email using python

I want to send outlook email via python and I found below script我想通过 python 发送 Outlook 电子邮件,我发现下面的脚本

import win32com.client
from win32com.client import Dispatch, constants
const=win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.BodyFormat = 2 
newMail.HTMLBody = "<HTML><BODY>Enter the <span style='color:red'>message</span> text here.</BODY></HTML>"
newMail.To = "my_email@email.com"
newMail.display()
newMail.Send()

Everything works fine untill newMail.Send() , it gives this error一切正常,直到newMail.Send() ,它给出了这个错误

Traceback (most recent call last):
  File "<ipython-input-46-7e8e370e48a8>", line 1, in <module>
    newMail.Send()
File "<COMObject CreateItem>", line 2, in Send
com_error: (-2147467260, 'Operation aborted', None, None)

您需要显示消息或发送消息,但不能同时发送 - 您的代码显示消息,然后立即发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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