WebJob Not Loading SendGridMail Assembly

感情迁移 提交于 2019-12-02 05:19:57

Please have a try to use mydemo code. I use the WebJobs.Extensions.SendGrid library,I have tested it. It works successfully in the WebJob after publishing to WebApp. The following is my test code and package.config file:

using System;
using System.Threading.Tasks;
using SendGrid.Helpers.Mail;
using SendGrid;
namespace TestWebJob
{
   class Program
   {
     static void Main(string[] args)
     {
        Console.WriteLine($"Start to run the Execute");
        Execute().Wait();
        Console.WriteLine($"Task finished");

     }
     static async Task Execute()
     {
        string apiKey = "your sendgrid API key";
        dynamic sg = new SendGridAPIClient(apiKey);
        Email from = new Email("a@testmail.com");//a test email address
        string subject = "Hello World from the SendGrid CSharp Library!";
        Email to = new Email("b@testmail.com");// another test email address
        Content content = new Content("text/plain", "Hello, Email!");
        Mail mail = new Mail(from, subject, to, content);
        dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
    }
  }
}

The packages.config file is as following:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.Azure.WebJobs" version="1.1.1" targetFramework="net452" />
  <package id="Microsoft.Azure.WebJobs.Core" version="1.1.1" targetFramework="net452" />
  <package id="Microsoft.Azure.WebJobs.Extensions" version="1.0.1" targetFramework="net452" />
  <package id="Microsoft.Azure.WebJobs.Extensions.SendGrid" version="1.0.1" targetFramework="net452" />
  <package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net452" />
  <package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net452" />
  <package id="Microsoft.Data.Services.Client" version="5.6.2" targetFramework="net452" />
  <package id="Microsoft.Tpl.Dataflow" version="4.5.24" targetFramework="net452" />
  <package id="Microsoft.Web.WebJobs.Publish" version="1.0.12" targetFramework="net452" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.8.0.0" targetFramework="net452" />
  <package id="ncrontab" version="2.0.0" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
  <package id="Sendgrid" version="8.0.5" targetFramework="net452" />
  <package id="SendGrid.CSharp.HTTP.Client" version="3.0.0" targetFramework="net452" />
  <package id="SendGrid.SmtpApi" version="1.3.1" targetFramework="net452" />
  <package id="System.Spatial" version="5.6.2" targetFramework="net452" />
  <package id="WindowsAzure.Storage" version="4.3.0" targetFramework="net452" />
</packages>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!