我开发了一个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建议的那样,我一直在浏览用户界面以了解我如何做到这一点,而且看起来并不容易(如果可能的话)。我做的一种方法是进入其他用户的日历并在那里创建一个新约会并添加被邀请者。通过从更改Advanced
时显示的“服务器设置”对话框中的More Settings...
按钮转到Account Settings
选项卡,可以添加该邮箱。此问题的另一个答案是如何在通过COM访问Outlook时将此邮箱用作默认发件人。