Office 365 Outlook Adapters in Action

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

This article presents all Office 365 Outlook adapters integrated in a simplified e-tailer scenario. The goal is to show one way to get started with the adapters in a minimal yet complete BizTalk application.

The adapters are:

- Office 365 Outlook Email

- Office 365 Outlook Calendar

- Office 365 Outlook Contact




A customer (Contoso) submits a purchase order (PO) by plain text email from an Office 365 account to an e-tailer (Fabrikam). The content of the email follows a custom purchase order xml schema defined by the e-tailer. One of the elements is a due date by which the order and an invoice will be sent.

Upon receiving the email, Fabrikam will do the following in parallel:
- Schedule sending the customer invoice.
- Create or update the customer contact information.
- Send a confirmation email to the customer.

On the due date, Fabrikam sends an invoice to Contoso.

Receive-Side: Processing the purchase order


Fabrikam implements the PO processing by using a BizTalk orchestration (shown below) and the construction of three messages: calendar event, contact, and email.




The PO follows the schema:



The order is received on an Office 365 email account, in plain text, with the following content in the email body:



<ns0:PurchaseOrder xmlns:ns0="http://CreateEventFromPurchaseOrder.PurchaseOrder"> <PONumber>PONumber_0</PONumber> <CustomerInfo> <Name>Contoso</Name> <Email></Email> </CustomerInfo> <Description> <Item>Item_0</Item> <Count>5</Count> </Description> <DueDate>2020-04-08</DueDate> </ns0:PurchaseOrder>




In the BizTalk message constructions, the PO xml schema is mapped to calendar event, contact and confirmation email schemas. For the calendar and contact schemas, we copied into our BizTalk project the schemas provided in the BizTalk installation folder under C:\Program Files (x86)\Microsoft BizTalk Server\SDK\Schemas:




The resulting maps are shown below:


Note that for contact, givenName must be provided.


The confirmation email also contains the original PO and an additional document as attachments. This is done by defining a multi-part message in the orchestration. The PO-to-email map takes care of creating the email body. Then, email attachments are added in the message assignment shape with the following code:



CreateConfirmationEmail.PO = PurchaseOrderMessage; CreateConfirmationEmail.PO(Microsoft.XLANGs.BaseTypes.ContentType) = "application/xml"; CreateConfirmationEmail.Receipt(Microsoft.XLANGs.BaseTypes.ContentType) = "text"; // NOTE: all message parts must be instanciated before the context properties are assigned. CreateConfirmationEmail(OfficeMail.Subject) = "Order Confirmation for " + PurchaseOrderMessage.PONumber + " due date " + System.String.Format("{0}", PurchaseOrderMessage.DueDate); CreateConfirmationEmail(OfficeMail.AttachedFiles) = "C:\\Brochure.xml"; CreateConfirmationEmail(OfficeMail.To) = PurchaseOrderMessage.CustomerInfo.Email;




All parts have to be instanciated before the context properties are assigned. For a complete list of the context properties, refer to Office 365 Outlook Email. Context properties for the calendar event (not used here) are also available and documented in Office 365 Outlook Calendar.


As a result, on the customer's side, the confirmation email will look like:



The orchestration is bound to an email receive port, and to calendar/contact/email send ports. The default XML receive pipeline is used in the email receive location. The setup is summarized below.




Send-Side: Sending invoice on the due date


Fabrikam gets notified on the due date that the invoice needs to be emailed to Contoso. The following orchestration is used to define the business flow:




Once again, the BizTalk message for the email is constructed in two steps. First, Office365OutlookCalendarReceive.xsd (copied from the SDK/Schemas folder) is mapped to a custom schema defining the invoice email content.




Then, the following message assignment shape is used to create the email subject and extract the recipient's email from the received calendar event, which corresponds to the second element in the attendee list (hence the [2] in the xpath):



CreateInvoiceMessage(OfficeMail.Subject) = "Order Invoice for " + ReceiveEventMessage.subject; CreateInvoiceMessage(OfficeMail.To) = xpath(ReceiveEventMessage, "string(/*[local-name()='Event' and namespace-uri()='']/*[local-name()='attendees' and namespace-uri()=''][2]/*[local-name()='emailAddress' and namespace-uri()='']/*[local-name()='address' and namespace-uri()='']/text())");




The orchestration is bound to a calendar receive port with a 1-day time horizon to get notified within 24h before the due date.




In our solution, we reuse the existing email send port bound to the first orchestration. However, a new email send port may be warranted if different default adapter properties (shown below) are required, or if invoices need to be sent from a different Office 365 email account.




In Summary


The Contoso-Fabrikam business scenario was implemented by integrating all Office 365 Outlook adapters in receive- and send-side transforms and orchestrations.


BizTalk artifacts are attached to this article for reference.

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.