[前情提要]
輸出與我興趣相符的會員的簡介到Queue裡面,等待郵件服務排成來發送
在這篇我們將串接第三方寄信API(SendGrid),從Azure Queue Storage裡取出資料,發送信件給我
這是一間電子郵件服務的公司,取得API KEY可以用他們提供的API發送信件
微軟Azure與它有良好界接(範例檔就是界接Send Grid),方便快速!
[Create New Key] => [Restricted Access] => [Mail Send]
複製申請的KEY(稍後結合Azure會用上)
Template預設的是與Send Grid界接,我們必須手動新增SendGrid的金鑰才能正常使用
run.csx
#r "SendGrid"
using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure.WebJobs.Host;
// The 'From' and 'To' fields are automatically populated with the values specified by the binding settings.
//
// You can also optionally configure the default From/To addresses globally via host.config, e.g.:
//
// {
// "sendGrid": {
// "to": "user@host.com",
// "from": "Azure Functions <samples@functions.com>"
// }
// }
public static Mail Run(TimerInfo myTimer, TraceWriter log)
{
var today = DateTime.Today.ToShortDateString();
log.Info($"Generating daily report for {today} at {DateTime.Now}");
Mail message = new Mail()
{
Subject = $"Daily Report for {today}"
};
// TODO: Customize this code to generate your specific mail message
var orderCount = 100;
Content content = new Content
{
Type = "text/plain",
Value = $"You had {orderCount} orders today!"
};
message.AddContent(content);
return message;
}
上篇我們簡單的對範例程式進行測試,在下篇我們會撰寫程式,去Queue裡存取我們的Message,再發信給我。
實作篇串接Queue發送Email連結在此:串接第三方寄信API(下篇)