exchangelib icon indicating copy to clipboard operation
exchangelib copied to clipboard

Sending invitation by delegate

Open shaktikshri opened this issue 7 years ago • 10 comments

Hi, I have delegate access to a mailbox. However when I create a calendar item using the following script,

credentials = Credentials('[email protected]', 'password')
account = Account(primary_smtp_address='[email protected]', credentials=credentials, autodiscover=True, access_type=DELEGATE)
attendees = ['[email protected]']
item = CalendarItem(
    account=account,
    folder=account.calendar,
    start=tz.localize(EWSDateTime(2018, 5, 10, 3, 0)),
    end=tz.localize(EWSDateTime(2018, 5, 10, 3, 30)),
    subject="Some meeting invitation",
    body="Please come to my meeting",
    required_attendees=attendees
)
item.save(send_meeting_invitations=SEND_TO_ALL_AND_SAVE_COPY)

and send it, it gets reflected as me as the organiser and not the primary email for which I have delegate access. Any way I can get this done?

shaktikshri avatar May 02 '18 08:05 shaktikshri

You should be able to set the organizer explicitly with organizer='[email protected]'. See also #340

ecederstrand avatar May 02 '18 08:05 ecederstrand

I have access as an editor to the primary email's calendar. However it is not getting reflected as him as the organiser even though I set it explicitly

shaktikshri avatar May 02 '18 08:05 shaktikshri

Let me check with all the rights on the primary's account, not just calendar. But its weird since I am able to do the same thing from within outlook, but not from the python library :/

shaktikshri avatar May 02 '18 08:05 shaktikshri

No luck :(

shaktikshri avatar May 02 '18 09:05 shaktikshri

I think we'll need a working example in e.g. C# or a trace of the XML requests and responses of a working interaction with Exchange to work out what we're doing differently.

ecederstrand avatar May 02 '18 09:05 ecederstrand

I suspect the item.save(send_meeting_invitations=SEND_TO_ALL_AND_SAVE_COPY) is saving it to the user's calendar and not the actual primary's email address. This is mentioned in the C# request for the EWS.

https://msdn.microsoft.com/en-us/library/office/dn641956(v=exchg.150).aspx#bk_createewsma

shaktikshri avatar May 02 '18 10:05 shaktikshri

I tried out sending the invitation with delegate permission using XML template, and it works perfectly fine. For other users who may find this issue, please use the below XML schema,

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
         xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <m:CreateItem SendMeetingInvitations="SendToAllAndSaveCopy">
      <m:SavedItemFolderId>
        <t:DistinguishedFolderId Id="calendar">
          <t:Mailbox>
            <t:EmailAddress>[email protected]</t:EmailAddress>
          </t:Mailbox>
        </t:DistinguishedFolderId>
      </m:SavedItemFolderId>
      <m:Items>
        <t:CalendarItem>
          <t:Subject>Team building exercise</t:Subject>
          <t:Body BodyType="HTML">Lets learn to really work as</t:Body>
          <t:ReminderMinutesBeforeStart>60</t:ReminderMinutesBeforeStart>
          <t:Start>2018-05-10T23:00:33.756+05:30</t:Start>
          <t:End>2018-05-10T23:30:33.756+05:30</t:End>
          <t:Location>Conference Room 12</t:Location>
          <t:RequiredAttendees>
            <t:Attendee>
              <t:Mailbox>
                <t:EmailAddress>[email protected]</t:EmailAddress>
              </t:Mailbox>
            </t:Attendee>
          </t:RequiredAttendees>
        </t:CalendarItem>
      </m:Items>
    </m:CreateItem>
  </soap:Body>
</soap:Envelope>

and this XML should be POST using the credentials of [email protected] for connecting to the exchange services.

I feel the definition of item.save is the one we need to update in exchangelib, since C# documentation mentions, meeting.Save(new FolderId(WellKnownFolderName.Calendar, "[email protected]"), SendInvitationsMode.SendToAllAndSaveCopy);

Note that when you save the item, the Save method call must identify the mailbox owner's Calendar folder. If the mailbox owner's Calendar folder is not specified, the meeting request gets saved to the delegate's calendar and not the mailbox owner's Calendar folder. You can include the mailbox owner's Calendar folder in the Save method call in two ways. We recommend that you instantiate a new instance of the FolderId object by using the WellKnownFolderName and the SMTP address of the mailbox owner.

meeting.Save(new FolderId(WellKnownFolderName.Calendar, "[email protected]"), SendInvitationsMode.SendToAllAndSaveCopy);

OR

Mailbox primary = new Mailbox("[email protected]"); Folder primaryCalendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, primary)); … meeting.Save(primaryCalendar.Id, SendInvitationsMode.SendToAllAndSaveCopy);

Source is here, https://msdn.microsoft.com/en-us/library/office/dn641956(v=exchg.150).aspx

shaktikshri avatar May 02 '18 16:05 shaktikshri

I certainly agree with you that we should be comparing the XML generated from the exchangelib code and this XML to see what is going wrong. Will update you on it once I check :)

shaktikshri avatar May 02 '18 16:05 shaktikshri

Thanks for the updates! I'm reopening the ticket to make sure it doesn't get lost.

ecederstrand avatar May 03 '18 06:05 ecederstrand

Hi @ShaktiKShrivastava

Can you capture the XML that exchangelib produces in the latest version (1.11.4)? I suspect this may have been fixed, but I'd like to be sure, and I don't have a test server with multiple accounts ATM.

ecederstrand avatar Aug 02 '18 11:08 ecederstrand

Clopsing this issue as outdated. Setting a parent folder as a DistinguishedFolderId with a specific mailbox has been supported for quite a while.

ecederstrand avatar Sep 12 '22 05:09 ecederstrand