Tuesday, September 20, 2016

Exception Handling block gives error - Use of unconstructed message

I got this compile time error today while trying to build the solution am working upon now. And this error was thrown by Exception Handling Block.

Use of unconstructed message

Why it happened

Upon exception, an email is sent to emailAdress which is available in the incoming message, the first message received in Orchestration (MSG_Main). For this that particular field is marked as distinguished and it is checked, if it is blank no mail sent and if not blank then send mail.


But exception block reports it as error when compiling the solution, for it the MSG_Main is not constructed. Its confusing as MSG_Main is received and that actually triggered the orchestration then why the error?

The reason is Exception block considers following - exception can occur anywhere within the scope, even before you receive the message, so the only thing available to exception block is the exception object from that scope(nothing else from that particular scope) and the things before the scope. And as can be seen from image below, the First Receive shape is in scope and that's the reason for error.

Use of unconstructed message reason

What to do

In order to get rid of this I moved the receive shape out of scope and error vanished!!!

moved the receive shape out of scope

Monday, September 19, 2016

Sending file as attachment using BizTalk Orchestration


The Simple Mail Transfer Protocol (SMTP) adapter is used to exchange information between a server running Microsoft BizTalk Server and other applications by means of the SMTP protocol. BizTalk Server can send messages to other applications by creating an e-mail message and delivering it to a specified e-mail address. BizTalk supports both ways - Static configuration and Dynamic configuration of SMTP adapter.

You would need to send email from Orchestration for various scenarios like dynamic mailto address/ Subject/Body or in workflow notification is to be send  where Subject changes depending upon  various scenarios ex. on success -- Subject is to be sent is "Transaction/Process completed successfully" and in error scenario "Transaction/Process failed" etc.

To demonstrate how to configure SMTP Port dynamically and how to add attachments, have used following scenario:


Keeping it simple, you receive a message which has details of email to be sent in it. You construct email message and configure SMTP adapter using those details.

Building the Solution

Create schema for message holding email details

create schema

Create orchestration

Create an orchestration containing a Receive shape to receive Email_Details message from a static one way Receive port  followed by a Construct message shape containing a Message assignment shape where SMTP adapter is configured dynamically, and a send shape to send Email message through Dynamic port(code below). We also need to create two message,one for the input message based on Email Details schema and one for the output message based on String datatype.

create orchestration

SMTP.Attachments is the property available with SMTP adapter which provides a way to pass the path of files to be attached. If more than one fie is to be attached then, paths can be concatenated using pipe(|).

Constructing Email message and configuring dynamically SMTP server

MSG_Email= System.String.Empty;

MSG_Email(SMTP.Subject) = MSG_EmailDetails.Subject;

MSG_Email(SMTP.From) = MSG_EmailDetails.FromAddress;

MSG_Email(SMTP.SMTPHost) = "DemoMachinePM";

MSG_Email(SMTP.EmailBodyText) = MSG_EmailDetails.Body;

MSG_Email(SMTP.EmailBodyTextCharset) = "UTF-8";

MSG_Email(SMTP.Attachments) = MSG_EmailDetails.Attachments;

//For sending email to cc address use below line of code

MSG_Email(SMTP.CC) = MSG_EmailDetails.CcAddress;

MSG_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";

Port_Dynamic_SendEmail(Microsoft.XLANGs.BaseTypes.Address) = "mailto:"+MSG_EmailDetails.ToAddress;

I have set MSG_Email as System.String, as I don't intend to do anything with BizTalk message(MSG_EmailDetails). In case I needed to send the BizTalk message as an attachment then I would set MSG_Email as System.Xml.XmlDocument and assign the MSG_EmailDetails to it.

MSG_Email = MSG_EmailDetails;

And to send this also as an attachment would add following code

MSG_Email(SMTP.MessagePartsAttachments) = 1;

The send port used to send email is set as Dynamic one way (only send) with Pass Thru pipeline and address is set to toAddress.

Deploy and Test

Sign the application and deploy it, create a Recieve port with Receive Location having XmlReceive Pipeline. Send port would be already available as it is created while deploying solution because of it's dynamic binding.

To test the application, create the instance of MSG_EmailDetails and populate it with values and drop the file at location which is binded to the receive location.

Case 1: Input file (with one attachment info)

<ns0:Email xmlns:ns0="http://EmailAttachmentDemo.EmailDetails">




  <Subject>Email with attachment from demo server</Subject>

  <Body>Dynamic Email with attachment from demo server.</Body>



Output (Email delivered with one attachment)
Email delivered with one attachment

Case 2: Input file (with two attachment info)

In order to sent multiple attachment, '|' (pipe) is used as delimeter(marked in red below sample)

<ns0:Email xmlns:ns0="http://EmailAttachmentDemo.EmailDetails">




  <Subject>Email with attachment from demo server</Subject>

  <Body>Dynamic Email with multiple attachment from demo server.</Body>



Output (Email delivered with two attachment)
Email delivered with two attachment
Case 3: Sending Email Message also as an attachment

For sending MSG_Email message as attachment use below line of code


               MSG_Email(SMTP.MessagePartsAttachments) = 1;

As can be seen mail is received by address in cc along with EmailMessage as attachment too

1.The location where attachments are, should be accessible
2.Toemail address must not be empty and its size must not exceed 256 characters
3.CCemail address size must not exceed 1024 characters

Download Sample

Sunday, September 18, 2016

The server response was 550 5.7.1 unable to relay for

While working on a demo solution for Email functionality of BizTalk, I created a a simple application in Admin Console, with a static send port configured with SMTP adapter. 

Send port gets invoked with arrival of trigger message from receive port, but mail wasn't sent due to following error 

 " The server response was 550 5.7.1 Unable to relay for ....."

The server response was 550 5.7.1 Unable to relay for ....

Below is the SMTP Adapter Handlers properties, there was no problem
SMTP Adapter Handlers properties

Why it happened

This is an error from your SMTP mail server. It indicates that your mail server is not configured to allow you to send mail through it and it could be for following reasons.

1.The outgoing mail server could not identify the sender.
2.There are some issues while authenticating the sender on the server and thus restricting them to send emails.
3.The receiver domain’s recipient policy has imposed restrictions on the sender’s domain.

relay restrictions
By default, the SMTP virtual server allows relaying only from authenticated users. This configuration is designed to prevent unauthorized users from using your SMTP server to relay mail. The virtual server's default configuration allows only authenticated computers to relay mail.

What to do

Go to IIS6.0 Manager –> SMTP Virtual Server Properties –> Go to Access tab-> Click on Relay button

IIS6.0 Manager –> SMTP Virtual Server Properties –> Go to Access tab-> Click on Relay button

Click on Add button and add the ip adress or domainname of machine which you want to be included in the list

add the ip adress or domainname of machine

add the ip adress or domainname of machine 1

add the ip adress or domainname of machine 2
That's it. Now mails are sent successfully.

Saturday, September 3, 2016

No BizTalk Configuration database(s) found on server XXXX

We have setup a dev env -- a Virtual machine where BizTalk and SQL Server are both installed on it. Development and deployment is done on it through RDC. 

As the number of team members increased we decided to install BizTalk development components on each team members local machine and after development done, deploy on the Server (VM) and for that we added all the users in BizTalk administrator group on the server.

But they were not able to deploy the application, due to following error  

  <No BizTalk Configuration database(s) found on server "xxxx”.>

It was strange because we were able to deploy on the server with same user login, and not when trying from their local machine.

Upon looking on following blog: https://blogs.msdn.microsoft.com/apacbiztalk/2015/11/02/error-no-biztalk-configuration-databases-found-on-server-when-deploy-biztalk-application-in-vs-if-your-account-is-removed-from-sysadmin-role-in-sql/

This issue does not occur in SQL server 2008 R2 but with SQL server 2012, the solution is to grant view any definition permission to specific user which needs to deploy BizTalk application in VS.

Query to be used:

USE master 

We used 

USE master 

GRANT VIEW ANY DEFINITION TO “BizTalk Administrator group”