简体   繁体   English

Python win32com.client - 只有当我打开 Outlook 时电子邮件才会发出

[英]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.

相关问题 Python win32com.client和outlook - Python win32com.client and outlook 使用 python 库 win32com.client 在没有任何许可的情况下发送 Outlook 电子邮件 - Send an outlook email without any permission using python library win32com.client Python Outlook 收件箱保存附件 win32com.client - Python Outlook inbox saving attachments win32com.client Python win32com.client发送电子邮件中嵌入的图像 - Python win32com.client send image embedded in email 使用 Python Win32Com.Client 发送电子邮件发送错误 - Sending Email with Python Win32Com.Client Send Error 使用python win32com.client dispatch或dispatchex阅读Outlook消息时绕过安全框 - Bypassing security box when reading outlook messages using python win32com.client dispatch or dispatchex python-尝试打开(大)Excel时win32com.client:pywintypes.com_error - Python - win32com.client: pywintypes.com_error when trying to open a (large) Excel 想从 Python 发送一个 Outlook email 和 win32com.client 从另一个 email 地址默认 email 地址 - Want to send an Outlook email from Python with win32com.client from a other email address that default email address 如何使用 python 和 win32com.client 从 Outlook 的电子邮件项目中访问 c​​c 电子邮件地址 - How to access cc email address from email items from outlook using python and win32com.client 在python中使用win32com.client时'无法打开ID文件' - 'Could not open the ID file' when using win32com.client in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM