【问题标题】:How do I create an Outlook meeting request with an alternate sender/organizer?如何使用备用发件人/组织者创建 Outlook 会议请求?
【发布时间】:2012-03-13 01:35:46
【问题描述】:

我开发了一个 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 = ['me@example.com']
    test_sender     = 'alternate@example.com'

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

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

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

【问题讨论】:

  • 只是问一个愚蠢的问题:这个功能可以通过 UI 使用吗?如果不是(而且我从未找到它),那么它也可能无法以编程方式进行。
  • 根本不是一个愚蠢的问题 - 我一直在通过 UI 尝试它,但运气不佳。但是,help.lockergnome.com/office/… 似乎认为通过弄乱 PR_RECIPIENT_FLAGS 是可能的。

标签: python outlook win32com


【解决方案1】:

根据this page,您可以代表其他人发送会议请求,但您需要有权访问该人的日历。其他人必须任命您为代表。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
相关资源
最近更新 更多