[英]Python win32com.client - Email only goes out when I have outlook open
I currently have a python script which I'm trying to automate to send an email out via my account.我目前有一个 python 脚本,我正在尝试自动通过我的帐户发送电子邮件。 I'm using the win23com.client library to do this, and really briefly this is what my code is doing:
我正在使用 win23com.client 库来执行此操作,实际上这就是我的代码正在执行的操作:
mail = outlook.CreateItem(0)
mail.To = (list of emails)
#mail.cc = x
mail.Subject = x
mail.HTMLBody = (python object with HTML code)
mail.Send()
When I run the above with Outlook closed, I get the following error code:当我在关闭 Outlook 的情况下运行上述程序时,出现以下错误代码:
com_error: (-2147467260, 'Operation aborted', None, None)
However if I run it with Outlook open it sends it out fine through my email account.但是,如果我在 Outlook 打开的情况下运行它,它会通过我的电子邮件帐户正常发送。 I'm guessing it must have an issue in authenticating my account with outlook closed, but my colleagues don't seem to be having the same issue on the same network.
我猜想在关闭 Outlook 的情况下验证我的帐户时肯定有问题,但我的同事在同一网络上似乎没有遇到同样的问题。
Any ideas?有任何想法吗?
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
message = 'Hello'
mail = outlook.CreateItem(0)
mail.To = 'email'
mail.Subject = 'This is a test'
mail.HTMLBody = message
mail.Send()
Check this.检查这个。 It works for me even with Outlook closed.
即使关闭 Outlook,它也适用于我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.