在Microsoft Azure网站中,我们如何使用SendGrid发送电子邮件?
答案 0 :(得分:5)
你需要获得SendGrid UserId&来自Azure的密钥,然后使用下面的代码发送电子邮件:
public void SendEmail(string emailTo, string emailSubject, string emailBody)
{
try
{
//Create the email object first, then add the properties.
SendGrid myMessage = SendGrid.GetInstance();
myMessage.AddTo(emailTo);
myMessage.From = new MailAddress("abc@xyz.com", "Abc Xyz");
myMessage.Subject = emailSubject;
myMessage.Text = emailBody;
// Create credentials, specifying your user name and password. (Use SendGrid UserId & Password
var credentials = new NetworkCredential("azure_xxxxxxxxxxxxxxx@azure.com", "xxxxxxxxxxxx");
// Create an Web transport for sending email.
var transportWeb = Web.GetInstance(credentials);
//Send the email.
transportWeb.DeliverAsync(myMessage);
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
了解更多信息