BizTalk: Sending Emails with the SMTP Adapter

by matt 22. January 2008 15:27

Overview

For a while now, I have been working on a project that uses a helper class to send any error emails out that may occur during document processing.  In order for the helper class to know the recipient and sender for the emails, I have been relying on a custom configuration file which is retrieved from the registry.  Now, I inherited this project, and whilst the configuration file was originally used for a great deal of settings, it is now only used for these email addresses.

Now - I'm actually running two versions of the same BizTalk Server solution in different applications on the same server.  As such, my method of locating the correct configuration file is not suitable.  So I start thinking:

Perhaps I should try using the SMTP Adapter to send my emails, I wonder how that works?

Solution

The first thing that we need to do is to configure the SMTP adapter.  Rather then delve too deep here, I'm just going to set 'lazy' values that will work for me, you'll probably need to get decent values of you IT services team.

  1. In the BizTalk Server Administrator, navigate to BizTalk Server 2006 Administration > BizTalk Server Group > Platform Settings.
  2. Double-click SMTP and then Right-click on BizTalkServerApplication (this may differ depending on your host name) and select Properties.
  3. In the General tab, click Properties.
  4. Fill in the details you need.  For this example, I have just used the following:
  5. SMTP Server Name localhost
    From (e-mail address) nottelling@you.com
    Server Authentication Do not authenticate

That should be enough to allow you BizTalk Server to send emails to the world (or at least to the mail queue).

We're going to need something to kick off the process, so I'll just have a receive port name 'SMTP Test Receive Port' with a receive location (I usually just use a file receive location for this type of thing, but just use whatever is easier for you)

Now I need to create a port that will create the emails to send.  To try this in its simplest form, I created a one-way send port that used the SMTP adapter for the primary transport.  So, lets do it:

  1. In BizTalk Server Administrator, navigate to BizTalk Server 2006 Administration > BizTalk Server Group > Test BizTalk Server Application > Send Ports.
  2. Right-click in the right pane and select New > Static One-Way Send Port....
  3. Give the port a nice name and then select the transport type as SMTP. Then click Configure.....
  4. In the SMTP Transport Properties dialogue General tab, set up a To address (and CC if you would like) and a subject for the email.  In this example, I'm not using any notification.
  5. In the SMTP Transport Properties dialogue Compose tab, set email body to Text and type something appropriate.
  6. In the SMTP Transport Properties dialogue Attachments tab, set Remaining BizTalk Server message parts to Attach all parts.
  7. Click OK.
  8. In the send port properties, add a filter on BTS.ReceivePortName is that of the Receive Port we created earlier ('SMTP Test Receive Port').
  9. Click OK.

Enable the receive location(s) and enlist and start the send port.  If we supply the receive location with a file/message then we should get an email sent through to the email address that we set up.  If the email doe snot arrive and BizTalk Server is not reporting any errors, you may need to talk to you IT Services team.

Now, that is the simple way to send an email, but at a guess, most people don't want all emails to have the same subject, body and recipients. 

How do we go about modifying these things from an orchestration?

It's actually quite simple, there are a number of properties available on the port inside orchestrations that may be set at run-time.  It's not thoroughly easy to find information about these properties if you just use Google, so you can find a link to the list of the SMTP adapter properties at the bottom of this article.

Using an expression shape (this will need to be inside a message construction),  you can just set the properties as follows:

Message_1(SMTP.Subject) = "I was set in the orchestration";
Message_1(SMTP.EmailBodyText) = "Hello, Mum!";

It is pretty much that simple. 

There are some properties you can't set (such as recipient), as these are specifically set in the send port, but you can add a CC.

Versions

References

Metadata

Tags:

BizTalk Server

Comments

8/6/2008 11:28:24 PM #

I follow the step as above.
I create a receive port which accept .txt file. After I drop the file in receive port I get the error "The published message could not be routed because no subscribers were found."  Do I need set anything in pipeline? or anything else?

Pravangsu Biswas |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar