【发布时间】:2021-03-23 19:23:26
【问题描述】:
我正在努力将不同的正文发送给多个收件人。
这是我想要做的:
我正在执行一个 SQL 查询,并在“执行 SQL 任务”中获取结果。
结果示例:
脚本如下所示:
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;
}
目前我得到的结果是完全不正确的。使用此脚本,所有接收者都将获得整个 DataTable。
我正在尝试将包含电子邮件“test.recepient@abc.com”的特定行发送到此电子邮件。
因此,基本上两行行将发送到“test.recepient@abc.com”,仅一行发送到“test2.recepient2@def.com”。
如果您有任何问题,请告诉我。期待建议和答案!谢谢!
【问题讨论】:
标签: c# datatable ssis sendmail script-task