Configuration of the BizTalk SMTP-Adapter via a dynamic port

How to configure a BizTalk dynamic SMTP send port, setting mail parameters and the recipient address via Message Assignment and Expression shapes.

For sending emails out of a BizTalk-Orchestration to varying recipients you can use a dynamic send port. The sending-parameters you can set directly in the orchestration.

You need a “Message Assignment” and an “Expression”-shape.

In the “Message Assignment”-shape you set the parameters for the smtp-stuff:

msgSend(SMTP.CC) = "xyz@sample.com; ...";
msgSend(SMTP.Subject) = "TESTMAIL: blabla";
msgSend(SMTP.From) = "BizTalk@sample.com";
msgSend(SMTP.SMTPHost) = "smtp.sample.com";
msgSend(SMTP.SMTPAuthenticate) = 0;

The recipient is configurable as the URI-address of the adapter as an property of the dynamic sending port itself in the “Expression”-shape:

portSend(Microsoft.XLANGs.BaseTypes.Address)=
  "mailto:abc@sample.com"

If you want set the recipient as the content of a message, a simple way is to use XPath like in this example:

portSend(Microsoft.XLANGs.BaseTypes.Address) =
  "mailto:" + 
  (System.String) xpath(msgSend, "string(/*[local-name()='Root' and namespace-uri()='http://SampleNamespace']/*[local-name()='To' and namespace-uri()=''])");

for a XML-document like

<Root>
  blabla
  <To>abc@sample.com</To>
</Root>