c# - 在 SSIS 包中将 SendGrid 与脚本任务一起使用
问题描述
通过使用 VS 2017,我创建了一个 SSIS 包,然后尝试将 SendGrid 与 Script Task 组件一起使用,但我一直有错误消息。错误消息是“调用的目标已引发异常”。以下是我的代码,请帮我看看它有什么问题。谢谢你。
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
static EmailAddress yao = new EmailAddress("user@sample.com", "User Sample");
static string template_id = "SendGridTemplateID";
static string _api_key = ConfigurationManager.AppSettings["SendGridKey"];
public void Main()
{
SendEmail().Wait();
Dts.TaskResult = (int)ScriptResults.Success;
}
static async Task SendEmail()
{
var client = new SendGridClient(_api_key);
var msg = new SendGridMessage();
msg.AddTo(new EmailAddress("Sample@user.com", "Sample User"));
msg.SetFrom(new EmailAddress("Sample@user.com", "Sample User"));
msg.SetTemplateData(GoogleLinkReport);
msg.SetTemplateId(template_id);
var response = await client.SendEmailAsync(msg);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
}
static GoogleLink GoogleLinkReport = new GoogleLink
{
header = "This is google link",
text = "Please click the button to open the link for google",
subject = "GoogleLink",
c2a_link = "https://www.google.com",
c2a_button = "Google Link"
};
public class GoogleLink
{
public string header;
public string text;
public string subject;
public string c2a_link;
public string c2a_button;
}
}
解决方案
推荐阅读
- c# - 我无法从另一个应用程序读取我的配置文件
- java - Spring Boot 应用程序启动失败,出现 2.0.0.RELEASE
- c# - pdfsharpcore:无法访问 MigraDoc 类
- nuxt.js - 在 nuxt 条件下无法读取未定义的属性 $store
- wget - Wget:下载特定的 HTML 文件
- machine-learning - PPO / TRPO 实施
- nginx - 配置nginx发出后台请求
- sql - SQL:比较具有常见多对多关系的多个表
- javascript - 将javascript值转换为大写
- javascript - 同步 flex 滑块 - flex-direction-nav(箭头)