问题描述
我正在使用 SendGrid 并且我的代码正在正确发送电子邮件,但是我需要遍历从数据库中检索到的对象,这是一个列表,里面有 4 个字符串和 2 个日期时间字段......所以一个表会很棒吗?,我尝试使用 sendgrid 文档中的表但没有用,现在我尝试在 dynamicTemplateData 内部进行迭代但没有成功......我的问题和请求是:如何从 C# 上的对象列表中检索数据并显示它在 SendGrid 电子邮件上?
@H_404_2@ public async static Task<string> SendMailAsync(List<EmailAddress> to,List<Adf_pipeline_log> pipelines,string rules)
{
List<Adf_pipeline_log> _pipelines = pipelines;
var _to = to;
var _rules = rules;
var apikey = "xxxxxxx"; // Service Account sendGrid
try
{
var client = new SendGridClient(apikey);
var msg = new SendGridMessage()
{
From = new EmailAddress("nor[email protected]","Pipelines Failed"),Subject = "List of pipelines Failed in the last execution.",PlainTextContent = "plain text",HtmlContent = "Here is the list that contains the Pipelines that have Failed: ",};
msg.AddTos(_to);
// If you require complex substitutions this [use case](USE_CASES.md#transactional-templates).
foreach( var item in _pipelines)
{
if(item.Activity_status == "Failed")
{
var dynamicTemplateData = new Adf_pipeline_log
{
Pipeline_name = item.Pipeline_name,Activity_name = item.Activity_name,Activity_start_time = item.Activity_start_time,Activity_end_time = item.Activity_end_time,Activity_status = item.Activity_status,Activity_error = item.Activity_error,};
msg.SetTemplateData(dynamicTemplateData);
}
}
var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)