none
Dynamic Email Body Format - BizTalk RRS feed

  • Question

  • I am trying to send a email dynamically , i have achieved sending email and attachment through dynamicall , but i am trying to format the fonts  using  HTML tags below  is the code , but i am not able to get the appropriate output , i dont want to use any class or pipeline component for this , appreciate if i get some help on this

    BizTalkError(SMTP.Subject) = EmailSubject;
    BizTalkError(SMTP.From) = EmailFrom;
    BizTalkError(SMTP.SMTPHost) = SMTPServer;
    BizTalkError(SMTP.EmailBodyTextCharset) = "utf-8";
    BizTalkError(SMTP.EmailBodyText) = "<b> Below is the Purchase Order error  = </b> "  + ErroCode+  "\n\n\n" + "<b><p><big>Please do Find the Attachment for the complete Error message  </big></p></b>";
    BizTalkError(SMTP.Attachments) = EmailTxt;
    BizTalkError(SMTP.MessagePartsAttachments)=2;
    BizTalkError(MIME.FileName)="ErrorMessage.xml";


    Sukra


    • Edited by sukra1234 Wednesday, February 1, 2017 7:19 PM
    Wednesday, February 1, 2017 7:19 PM

Answers

  • Hi ,

    You can use rawString to custom format you email .Code for rawString can be found at MSDN link below

    https://msdn.microsoft.com/en-us/library/ee253435%28v=bts.10%29.aspx?f=255&MSPPError=-2147217396 

    and the process is simply been described at https://msdn.microsoft.com/en-us/library/ee253436(v=bts.10).aspx


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    Wednesday, February 1, 2017 8:51 PM
  • Hi Sukra,

    You just need to create a new message and initialize it in a message assignment shape like this:

    The key parts to notice here is how to just create into a StringBuilder the entire HTML message content, constructed dynamically. Once that's done, assign the resulting string to the RawString object in out EmailBody member of the email and set the part's ContentType Context property to "text/html".

    msgbody = new System.Text.StringBuilder();
    msgbody.AppendLine("<html><body>");
    msgbody.AppendLine("<p>The attached document failed on processing in BizTalk Server.</p>");
    msgbody.AppendLine("<p><b>Error details:</b></p><p>");
    msgbody.AppendLine("Error Description: <i>" + FailedMessage(ErrorReport.Description) + "</i><br/>");
    //msgbody.AppendLine("Message Type: " + FailedMessage(ErrorReport.MessageType) + "<br/>");
    msgbody.AppendLine("Error Type: " + FailedMessage(ErrorReport.ErrorType) + "<br/>");
    msgbody.AppendLine("Failure Category: " + System.Convert.ToString(FailedMessage(ErrorReport.FailureCategory)) + "<br/>");
    msgbody.AppendLine("Failure Code: " + FailedMessage(ErrorReport.FailureCode) + "<br/>");
    msgbody.AppendLine("Receive Port Name: " + FailedMessage(ErrorReport.ReceivePortName) + "<br/>");
    msgbody.AppendLine("Receive Location: <b>" + FailedMessage(ErrorReport.InboundTransportLocation) + "</b></p>");
    msgbody.AppendLine("</body></html>");
    EMail.EmailBody = new Microsoft.Samples.BizTalk.XlangCustomFormatters.RawString(msgbody.ToString());
    EMail.EmailBody(Microsoft.XLANGs.BaseTypes.ContentType) = "text/html";
    EMail.OriginalMessage = FailedMessage;
    EMail(SMTP.Subject) = "Failed error message notification";
    EMail(SMTP.From) = "someone@somewhere.com";
    EMail(SMTP.EmailBodyFileCharset) = "UTF-8";
    EMail(SMTP.SMTPHost) = "localhost";
    EMail(SMTP.MessagePartsAttachments) = 2;

    You can also refer https://www.codeproject.com/articles/36210/sending-an-html-formatted-e-mail-message-from-bi.

    You may choose to create a .Net Component where you store the base HTML message as a template and replace the variables with {0}.... etc. Then create a method where you pass the values and get the formatted HTML back with the values. This you can then assign to the multi-part message of type rawstring.



    Rachit Sikroria (Microsoft Azure MVP)


    Thursday, February 2, 2017 3:31 AM
    Moderator

All replies

  • Hi ,

    You can use rawString to custom format you email .Code for rawString can be found at MSDN link below

    https://msdn.microsoft.com/en-us/library/ee253435%28v=bts.10%29.aspx?f=255&MSPPError=-2147217396 

    and the process is simply been described at https://msdn.microsoft.com/en-us/library/ee253436(v=bts.10).aspx


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    Wednesday, February 1, 2017 8:51 PM
  • Hi Sukra,

    You just need to create a new message and initialize it in a message assignment shape like this:

    The key parts to notice here is how to just create into a StringBuilder the entire HTML message content, constructed dynamically. Once that's done, assign the resulting string to the RawString object in out EmailBody member of the email and set the part's ContentType Context property to "text/html".

    msgbody = new System.Text.StringBuilder();
    msgbody.AppendLine("<html><body>");
    msgbody.AppendLine("<p>The attached document failed on processing in BizTalk Server.</p>");
    msgbody.AppendLine("<p><b>Error details:</b></p><p>");
    msgbody.AppendLine("Error Description: <i>" + FailedMessage(ErrorReport.Description) + "</i><br/>");
    //msgbody.AppendLine("Message Type: " + FailedMessage(ErrorReport.MessageType) + "<br/>");
    msgbody.AppendLine("Error Type: " + FailedMessage(ErrorReport.ErrorType) + "<br/>");
    msgbody.AppendLine("Failure Category: " + System.Convert.ToString(FailedMessage(ErrorReport.FailureCategory)) + "<br/>");
    msgbody.AppendLine("Failure Code: " + FailedMessage(ErrorReport.FailureCode) + "<br/>");
    msgbody.AppendLine("Receive Port Name: " + FailedMessage(ErrorReport.ReceivePortName) + "<br/>");
    msgbody.AppendLine("Receive Location: <b>" + FailedMessage(ErrorReport.InboundTransportLocation) + "</b></p>");
    msgbody.AppendLine("</body></html>");
    EMail.EmailBody = new Microsoft.Samples.BizTalk.XlangCustomFormatters.RawString(msgbody.ToString());
    EMail.EmailBody(Microsoft.XLANGs.BaseTypes.ContentType) = "text/html";
    EMail.OriginalMessage = FailedMessage;
    EMail(SMTP.Subject) = "Failed error message notification";
    EMail(SMTP.From) = "someone@somewhere.com";
    EMail(SMTP.EmailBodyFileCharset) = "UTF-8";
    EMail(SMTP.SMTPHost) = "localhost";
    EMail(SMTP.MessagePartsAttachments) = 2;

    You can also refer https://www.codeproject.com/articles/36210/sending-an-html-formatted-e-mail-message-from-bi.

    You may choose to create a .Net Component where you store the base HTML message as a template and replace the variables with {0}.... etc. Then create a method where you pass the values and get the formatted HTML back with the values. This you can then assign to the multi-part message of type rawstring.



    Rachit Sikroria (Microsoft Azure MVP)


    Thursday, February 2, 2017 3:31 AM
    Moderator
  • Thursday, February 2, 2017 6:12 AM
    Moderator