python win32com Outlook 2013 SendUsingAccount 返回异常 [英] python win32com outlook 2013 SendUsingAccount return exception

查看:57
本文介绍了python win32com Outlook 2013 SendUsingAccount 返回异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 python 和 win32com api 处理简单的邮件自动化时,我遇到了 SendUsingAccount 问题.它被忽略了,或者更糟糕的是,当我从 Windows 7 升级到 Windows 10 时产生错误.

While working on a simple mail automation with python and win32com api, I had an issue with SendUsingAccount. It was ignored or, worse, generating an error when I upgraded from windows 7 to windows 10.

这是我的原始代码

import win32com.client

o = win32com.client.Dispatch("Outlook.Application")
oacctouse = None
for oacc in o.Session.Accounts:
    if oacc.SmtpAddress == "sender@mail.com":
        oacctouse = oacc
        break
Msg = o.CreateItem(0)
if oacctouse:
    Msg.SendUsingAccount = oacctouse
if to:
    Msg.To = ";".join(to)
if cc:
    Msg.CC = ";".join(cc)
if bcc:
    Msg.BCC = ";".join(bcc)

Msg.HTMLBody = ""

Msg.Send()

导致以下错误:回溯(最近一次调用最后一次):文件C:Program Files (x86)JetBrainsPyCharm 5.0.3helperspydevpydevd_exec.py",第 3 行,在 Exec 中exec exp in global_vars, local_vars文件",第 1 行,在setattr 中的文件C:Python27libsite-packageswin32comclientdynamic.py",第 560 行self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value)com_error: (-2147417851, 'x83Tx81[x83ox81[x82xc9x82xe6x82xc1x82xc4x97xe1x8aOx82xaax95xaax95xb3x82xeax82xdcx82xb5x82xbdx81B',无,无)

Resulting in the following error: Traceback (most recent call last): File "C:Program Files (x86)JetBrainsPyCharm 5.0.3helperspydevpydevd_exec.py", line 3, in Exec exec exp in global_vars, local_vars File "", line 1, in File "C:Python27libsite-packageswin32comclientdynamic.py", line 560, in setattr self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value) com_error: (-2147417851, 'x83Tx81[x83ox81[x82xc9x82xe6x82xc1x82xc4x97xe1x8aOx82xaax95xd4x82xb3x82xeax82xdcx82xb5x82xbdx81B', None, None)

我的系统是日语.

我将在下面回答我的问题.

I will answer my issue below.

推荐答案

所以,我偶然在 此线程非常底层(大部分是针对 VBA 的,但最后一个帖子解决了 python 问题).

So, I found the solution to my problem by chance on this thread at the very bottom (most of it is for VBA but the last post solved the python issue).

这是工作代码

import win32com.client

o = win32com.client.Dispatch("Outlook.Application")
oacctouse = None
for oacc in o.Session.Accounts:
    if oacc.SmtpAddress == "sender@mail.com":
        oacctouse = oacc
        break
Msg = o.CreateItem(0)
if oacctouse:
    Msg._oleobj_.Invoke(*(64209, 0, 8, 0, oacctouse))  # Msg.SendUsingAccount = oacctouse

if to:
    Msg.To = ";".join(to)
if cc:
    Msg.CC = ";".join(cc)
if bcc:
    Msg.BCC = ";".join(bcc)

Msg.HTMLBody = ""

Msg.Send()

这篇关于python win32com Outlook 2013 SendUsingAccount 返回异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆