如何创建与备用发件人/组织者的 Outlook 会议请求?

发布于 2025-01-08 17:30:06 字数 3147 浏览 1 评论 0原文

我开发了一个 Python 应用程序来自动发送电子邮件和内部办公室活动的会议请求。为了将这些信息与我的常规通信分开,我们设置了一个备用电子邮件地址,我可以用它来发送官方公告。我已经修改了我的应用程序,通过使用备用发件人的 SentOnBehalfOfName 来处理电子邮件的此问题 - 但是,我无法为会议请求复制此操作。我基于一系列网络搜索的尝试如下。但是,在运行此命令时,我收到错误:

Traceback (most recent call last):
  File "mailer_test.py", line 49, in <module> test_sender)
  File "mailer_test.py", line 38, in send_meeting_request
    mtg.Send()
  File "<COMObject CreateItem>", line 2, in Send
pywintypes.com_error: (-2147024809, 'The parameter is incorrect.', None, None)

当我添加备用发件人的选项时会发生这种情况 - 删除此结果会导致消息从我的帐户成功发送。重现错误的测试代码如下 - 我已经删除了我的实际电子邮件地址,但其他所有内容都是相同的。

import win32com.client

OUTLOOK_APPOINTMENT_ITEM  = 1
OUTLOOK_MEETING           = 1
OUTLOOK_ORGANIZER         = 0
OUTLOOK_OPTIONAL_ATTENDEE = 2

ONE_HOUR       = 60
THIRTY_MINUTES = 30

OUTLOOK_FORMAT = '%m/%d/%Y %H:%M'
outlook_date   = lambda dt: dt.strftime(OUTLOOK_FORMAT)

class OutlookClient(object):
    def __init__(self):
        self.outlook = win32com.client.Dispatch('Outlook.Application')

    def send_meeting_request(self, subject, time, location, recipients, body,
                             sender=None):
        mtg = self.outlook.CreateItem(OUTLOOK_APPOINTMENT_ITEM)
        mtg.MeetingStatus = OUTLOOK_MEETING
        mtg.Location = location

        if sender:
            # Want to set the sender to an address specified in the call
            # This is the portion of the code that does not work
            organizer      = mtg.Recipients.Add(sender)
            organizer.Type = OUTLOOK_ORGANIZER
        for recipient in recipients:
            invitee      = mtg.Recipients.Add(recipient)
            invitee.Type = OUTLOOK_OPTIONAL_ATTENDEE

        mtg.Subject                    = subject
        mtg.Start                      = outlook_date(time)
        mtg.Duration                   = ONE_HOUR
        mtg.ReminderMinutesBeforeStart = THIRTY_MINUTES
        mtg.ResponseRequested          = False
        mtg.Body                       = body
        mtg.Send()

if __name__ == "__main__":
    import datetime
    ol = OutlookClient()
    meeting_time = datetime.datetime.now() + datetime.timedelta(hours=3)
    test_recipients = ['[email protected]']
    test_sender     = '[email protected]'

    ol.send_meeting_request('Test Meeting', meeting_time, 'Nowhere',
                            test_recipients, 'This is a test meeting.',
                            test_sender)

注意:这与这个问题不是同一个问题,因为我我没有使用 C#,也没有尝试在事后编辑会议请求。

更新: 正如 Marnix Klooster 所建议的,我一直在浏览 UI,看看如何做到这一点,这似乎并不容易(如果可能的话)。我这样做的一种方法是进入其他用户的日历并在那里创建一个新约会并添加受邀者。通过从更改帐户设置时显示的服务器设置对话框中的更多设置...按钮转至高级选项卡来添加该邮箱。此问题的另一个答案是在通过 COM 访问 Outlook 时如何使用此邮箱作为默认发件人。

I've developed a Python application to automate sending emails and meeting requests for internal office events. To keep these separate from my regular communications, we've set up an alternate email address that I can use to send the official announcements. I've modified my application to handle this for emails by using the SentOnBehalfOfName for the alternate sender - however, I haven't been able to duplicate this for meeting requests. My attempt based on a series of web searches follows. When running this, though, I get the error:

Traceback (most recent call last):
  File "mailer_test.py", line 49, in <module> test_sender)
  File "mailer_test.py", line 38, in send_meeting_request
    mtg.Send()
  File "<COMObject CreateItem>", line 2, in Send
pywintypes.com_error: (-2147024809, 'The parameter is incorrect.', None, None)

This happens when I add in the option for an alternate sender - removing this results in the message sent successfully from my account. The test code which reproduces the error is below - I've removed my actual email address, but everything else is the same.

import win32com.client

OUTLOOK_APPOINTMENT_ITEM  = 1
OUTLOOK_MEETING           = 1
OUTLOOK_ORGANIZER         = 0
OUTLOOK_OPTIONAL_ATTENDEE = 2

ONE_HOUR       = 60
THIRTY_MINUTES = 30

OUTLOOK_FORMAT = '%m/%d/%Y %H:%M'
outlook_date   = lambda dt: dt.strftime(OUTLOOK_FORMAT)

class OutlookClient(object):
    def __init__(self):
        self.outlook = win32com.client.Dispatch('Outlook.Application')

    def send_meeting_request(self, subject, time, location, recipients, body,
                             sender=None):
        mtg = self.outlook.CreateItem(OUTLOOK_APPOINTMENT_ITEM)
        mtg.MeetingStatus = OUTLOOK_MEETING
        mtg.Location = location

        if sender:
            # Want to set the sender to an address specified in the call
            # This is the portion of the code that does not work
            organizer      = mtg.Recipients.Add(sender)
            organizer.Type = OUTLOOK_ORGANIZER
        for recipient in recipients:
            invitee      = mtg.Recipients.Add(recipient)
            invitee.Type = OUTLOOK_OPTIONAL_ATTENDEE

        mtg.Subject                    = subject
        mtg.Start                      = outlook_date(time)
        mtg.Duration                   = ONE_HOUR
        mtg.ReminderMinutesBeforeStart = THIRTY_MINUTES
        mtg.ResponseRequested          = False
        mtg.Body                       = body
        mtg.Send()

if __name__ == "__main__":
    import datetime
    ol = OutlookClient()
    meeting_time = datetime.datetime.now() + datetime.timedelta(hours=3)
    test_recipients = ['[email protected]']
    test_sender     = '[email protected]'

    ol.send_meeting_request('Test Meeting', meeting_time, 'Nowhere',
                            test_recipients, 'This is a test meeting.',
                            test_sender)

Note: This is not the same problem as this question, since I'm not using C# and I'm also not trying to edit the meeting request after the fact.

Update:
As Marnix Klooster suggested, I've been looking through the UI to see how I can do this, and it doesn't appear to be easy (if even possible). The one way I have done it is to go into the other user's calendar and create a new appointment there and add invitees. That mailbox is added by going to the Advanced tab from the More Settings... button in the Server Settings dialog displayed when changing the Account Settings. An alternate answer to this question would be how to use this mailbox as the default originator when accessing Outlook via COM.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芯好空 2025-01-15 17:30:06

根据 此页面,您可以代表其他人发送会议请求,但您需要有权访问该人的日历。对方必须指定您为代表。

According to this page, you can send meeting requests on behalf of another person, but you need to have access to that person's calendar. The other person must appoint you as a delegate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文