我开发了一个Python应用程序来自动发送内部办公事件的电子邮件和会议请求。为了将这些与我的常规通信分开,我们已经设置了一个备用电子邮件地址,我可以使用该地址发送正式通知。我修改了我的应用程序,通过将SentOnBehalfOfName
用于替代发件人来处理电子邮件 - 但是,我无法为会议请求复制此内容。我基于一系列网络搜索的尝试如下。当运行这一点,虽然,我得到的错误:如何使用替代发件人/组织者创建Outlook会议请求?
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)
注:这是不一样的问题,因为this question,因为我没有使用C#,我还没有尝试编辑在事后的会议请求。
更新: 作为马尼克斯克卢斯特建议,我一直在寻找通过UI,看我怎么能做到这一点,它似乎并不容易(如果甚至有可能)。我已经完成的一种方式是进入其他用户的日历并在那里创建一个新的约会并添加被邀请者。通过在更改Account Settings
时显示的“服务器设置”对话框中的More Settings...
按钮转到Advanced
选项卡来添加该邮箱。这个问题的另一个答案是如何在通过COM访问Outlook时使用此邮箱作为默认创建者。
只是问一个愚蠢的问题:这个功能是否可以通过UI?如果不是(我从来没有找到它),那么它也可能是不可能编程的。 – 2012-02-29 07:22:48
根本不是一个愚蠢的问题 - 我一直试图通过UI没有太多的运气。但是,http://help.lockergnome.com/office/set-meeting-organizer--ftopict697177.html似乎认为可能通过与PR_RECIPIENT_FLAGS混淆。 – 2012-02-29 15:48:00