Thursday, June 30, 2011

How to send Email in HTML Format?

If you get a requirement to send an email from Siebel, the very simple way is to make use of OOB business service, i.e "Outbound Communications Manager" with the method "SendMessage". Following input parameters would be enough for this purpose:

a) MsgToList
b) MsgSubject
c) MsgBody
d) CommProfile

Here below is the working example for the same:

var inp = TheApplication().NewPropertySet();
var out = TheApplication().NewPropertySet();
var svc = TheApplication().GetService("Outbound Communications Manager");
inp.SetProperty("CommProfile", "SiebelMantra Profile");
inp.SetProperty("MsgToList", siebelmantra@gmail.com);
inp.SetProperty("MsgSubject", "Test Email");
inp.SetProperty("MsgBody", "This is a test email");
svc.InvokeMethod("SendMessage", inp, out);

Here below is the email I received:

So, everything is working as desired, but what if you are required to send a HTML email which contains text with different colors and formatting? Well, one can quickly answer that you can use "MsgHTMLBody" argument in the above code instead of using "MsgBody". Yes, that is correct but the only it got is that you need to pass the complete HTML code as the value to this argument, but wait a minute why to take all this pain when Siebel provides a mechanism to keep the email template in HTML format for you and just need to create it from the UI. Yes, you guessed it right, I am talking about Administration - Communications -> All Templates view.

Just create a new Email Template with :
a) Status = Active
b) HTML Template = True

Now, here below is the small code to make this work:

var inp = TheApplication().NewPropertySet();
var out = TheApplication().NewPropertySet();
var svc = TheApplication().GetService("Inbound E-mail Database Operations");
inp.SetProperty("BusObj", "Comm Package");
inp.SetProperty("BusComp", "Comm Package");
inp.SetProperty("Name", "Test");
inp.SetProperty("QueryFields", "Name");
inp.SetProperty("ValueFields", "Template Text");
svc.InvokeMethod("FindRecord", inp, out);

var inp1 = TheApplication().NewPropertySet();
var out1 = TheApplication().NewPropertySet();
var svc1 = TheApplication().GetService("Outbound Communications Manager");
inp1.SetProperty("CommProfile", "SiebelMantra Profile");
inp1.SetProperty("MsgToList", siebelmantra@gmail.com);
inp1.SetProperty("MsgSubject", "Test Email");
inp1.SetProperty("MsgHTMLBody", out.GetProperty("Template Text"));
svc1.InvokeMethod("SendMessage", inp1, out1);

and when I executed the above code, here below is the email in HTML format I received in my Inbox:

Siebel makes life so colorful, isn't it ;)