我正在尝试使用 WebJobs 将 SendGrid 集成到 .Net 4.5 应用程序。
我做了发送基本电子邮件所需的基本配置。我正在尝试在我的本地机器上运行和测试它。我不知道如何将消息推送到队列。到目前为止,我无法升级应用程序的 .Net 版本。如果可以在不使用 webjobs 的情况下做到这一点,那也很好。
程序.cs
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
config.Queues.MaxDequeueCount = 2;
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(4);
config.Queues.BatchSize = 2;
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseSendGrid();
var host = new JobHost(config);
host.RunAndBlock();
}
函数.cs
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log, [SendGrid(From = "no-reply@company.com", To = "employee@company.com")] out Mail mail)
{
log.WriteLine(message);
mail = new Mail();
var personalization = new Personalization();
personalization.AddBcc(new Email("employee@company.com"));
mail.AddPersonalization(personalization);
mail.Subject = "Test Email Subject";
mail.AddContent(new Content("text/html", $"The message '{message}' was successfully processed."));
}
发现以下函数: SendGrid_Test_002.Functions.ProcessQueueMessage ServicePointManager.DefaultConnectionLimit 设置为默认值 2。这可以限制 Azure Storage 等服务的连接吞吐量。有关详细信息,请参阅https://aka.ms/webjobs-connections。作业主机已启动
我在控制台上得到了这个。
提前致谢 :)