I am trying to query the database and send the content in the body of the email. The content is Order and the details for each users. I am trying to call a script task to compose the body and I am using the content in the Send Email Task. The script is like below
namespace ST_c2e68b3edd6842c4a6554376987c97c1
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
}
public void Main()
{
var data = Dts.Variables["User::EmailData"].Value;
OleDbDataAdapter da = new OleDbDataAdapter();
DataTable dt = new DataTable();
da.Fill(dt, data);
Dts.Variables["User::EmailMessage"].Value = ConvertDataTableToHTML(dt);
Dts.TaskResult = (int)ScriptResults.Success;
}
public static string ConvertDataTableToHTML(DataTable dt)
{
string html = "<table border ='1'>";
//add header row
html += "<tr>";
for (int i = 0; i < dt.Columns.Count; i++)
html += "<th>" + dt.Columns[i].ColumnName + "</th>";
html += "</tr>";
//add rows
for (int i = 0; i < dt.Rows.Count; i++)
{
html += "<tr style='color:blue;'>";
for (int j = 0; j < dt.Columns.Count; j++)
html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
html += "</tr>";
}
html += "</table>";
return html;
}
}
}
Where the User::EmailMessage is a string which I am using the Email body like
But in my email the body looks like
How can I show the HTML in the email properly. Any help is greatly appreciated