通过使用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;
}
}