SMTP Fun With BizTalk Server 2006

Doing anything particularly fancy with the SMTP adapter in BizTalk Server 2004 often involved invoking helper classes (like SMTPUtils) or the like. I spent time this weekend (yes, this weekend) working with the SMTP adapter for some material I'm presenting.

The first thing I set up was the full email environment in my virtual machine. Using the SMTP service in IIS, and then installing the Windows Server 2003 optional bits for POP3, I'm able to send email via the adapter, and receive it in Outlook 2003 via the POP3 service. Pretty sweet setup for one machine.

You may have seen the screenshots of the new property windows of the SMTP adapter. Now you can choose what to use as the email message body (the BizTalk message, or any other text), and point to an external *.htm file for the body. You can also play around with attachments and what message parts to attach. Much easier than the old way. However, you may not want to set a whole lot of values in the generic send port configuration itself, but rather, you may want to dynamically determine various parameters (To, Subject, Body, etc) on the fly. So my orchestration uses the following code to dynamically setup the SMTP send action:

NewOrder_XML_Outgoing(SMTP.SMTPHost) = "WS03VSSQL05";
NewOrder_XML_Outgoing(SMTP.From) = "biztalkadmin@WS03VSSQL05";
NewOrder_XML_Outgoing(SMTP.Subject) = "Order Accepted";
NewOrder_XML_Outgoing(SMTP.EmailBodyFile) = @"C:\Projects\Microsoft.Demo.Roadshow\ApprovedMsg.htm";
NewOrder_XML_Outgoing(SMTP.MessagePartsAttachments) = 1;

The "1" that the SMTP.MessagePartsAttachment is set to allows me to attach the BizTalk body as the attachment. I use a pipeline to add an XML processing instruction to the outbound message, so that when the email is received in Outlook, it opens up the message in a fancy InfoPath form. I'm still playing around with how to dynamically do HTML message bodies since I would suspect that except for canned responses, you'd probably want some dynamic content instead of pointing to a static file. Of course you could use a helper component to generate a context-specific *.html file in the temp directory, and then dynamically point to that, but there's got to be an easier way. If you see one, lemme know.

So with BizTalk Server 2006, it is now EASY to define message style and attachment parameters to send out useful messages for end users.