2012-02-22 457 views
6

我開發了一個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時使用此郵箱作爲默認創建者。

+1

只是問一個愚蠢的問題:這個功能是否可以通過UI?如果不是(我從來沒有找到它),那麼它也可能是不可能編程的。 – 2012-02-29 07:22:48

+0

根本不是一個愚蠢的問題 - 我一直試圖通過UI沒有太多的運氣。但是,http://help.lockergnome.com/office/set-meeting-organizer--ftopict697177.html似乎認爲可能通過與PR_RECIPIENT_FLAGS混淆。 – 2012-02-29 15:48:00

回答

-1

根據this page,您可以代表另一個人發送會議請求,但您需要有權訪問該人的日曆。另一個人必須任命你爲代表。

+0

這是正確的。第一步就是「打開對方的日曆」。我可以手動做到這一點,但有沒有辦法使它自動化? – 2012-03-12 15:29:44

+0

使用交換API:http://docs.activestate.com/activepython/2.4/pywin32/exchange.html? – 2012-03-12 19:38:19

相關問題