I am struggling to send a different body to multiple recepients.
Here's what I'm trying to do:
I have a SQL query that I am executing and getting the results in the "Execute SQL Task".
The result example:
The script looks like this:
public void Main()
{
// TODO: Add your code here
Variables varCollection = null;
Dts.VariableDispenser.LockForWrite("User::QueryResult");
Dts.VariableDispenser.GetVariables(ref varCollection);
string result = varCollection["User::QueryResult"].Value.ToString();
var data = varCollection["User::QueryResult"].Value;
OleDbDataAdapter da = new OleDbDataAdapter();
DataTable dt = new DataTable();
da.Fill(dt, varCollection["User::QueryResult"].Value);
foreach (DataRow row in dt.Rows)
{
string body = string.Empty;
string emailTo = string.Empty;
string subject = string.Empty;
try
{
List<string> final = new List<string>();
foreach (DataRow row2 in dt.Rows)
{
emailTo = row2["Email"].ToString();
subject = row2["SalesOrder"].ToString() + " products have been approved";
List<string> temp = new List<string>();
if (row2[2].ToString() == emailTo)
{
temp.Add(row2.ToString());
final.Add(string.Join("\t", temp));
}
body = string.Join("\r\n", final);
}
SendMailMessage("ssisnotifier@admin.com", emailTo, subject, body, true, credetnials);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
At the moment the result which I am getting is totally incorrect. With this script, all of the recepients will get whole DataTable.
I am trying to send the specific rows that contain the email "test.recepient@abc.com" to this email.
So bascially two rows will be sent to "test.recepient@abc.com" and only one to "test2.recepient2@def.com".
Please let me know if you have any questions. Looking forward to suggestions and answers! Thanks!