Thursday, February 02, 2006

BizTalk 2006 SMTP Adapter

I found a couple of great articles on using the SMTP adapter on Richard Seroter's blog here, and Tomas Restrepo's blog here. What follows are a couple of things that I had to find elsewhere.
For the following examples, I assume you've already created 2 multipart messages EmailIn and EmailOut, each with a body part and an attachment part called Remainder. EmailIn has been used to receive an email using the POP3 adapter (see my previous post), and EmailOut is for sending an email out via SMTP. I also assume that you've at least partly built the EmailOut message, see the 2 links above if you don't know how.

To set the filename for the attachment:
EmailOut.Remainder(MIME.FileName) = "MySpecialTitle.XML";
To set the subject of the outgoing email from the incoming email:
EmailOut(SMTP.Subject) = EmailIn(POP3.Subject);
By the way, these need to be done in a constructor for EmailOut.

To send your email to an address that is to be configured at run-time, assuming that you've managed to get the correct address into the variable emailAddress:
  1. Creating a dyamic port
  2. Create an expression shape
  3. Enter code that looks like this in the expression shape:
    DynamicPort(Microsoft.XLANGs.BaseTypes.Address) = "mailto:" + emailAddress;

It took me a while to figure out how this could work, my guess is that the "mailto:" prefix somehow indicates to BizTalk that it should use SMTP for that port, just as http tells your browser to use port 80.

Hopefully you can extrapolate other things that you might need from the links and these examples.

4 comments:

Unknown said...

Can we use Macros in Atatched file name? MIME.FileName = "Invoice%datetime.tz%.txt"

Steve Harclerode said...

Remember, all this is inside an expression shape in an orchestration. As far as I know, you can't use macros in the way that you are asking. But you can use regular .Net string functions to accomplish the same thing.

Anonymous said...

Lots of extremely good reading here, thank you! I was looking on yahoo when I found your article, I’m going to add your feed to Google Reader, I look forward to more from you.

Anonymous said...

FYI - you should be able to still use a late-bound(specify later) or direct-bound port with this and the adapter properties set within your orchestration will overwrite properties set in the admin console.