在Microsoft Azure网站中,我们如何使用SendGrid发送电子邮件?
最佳答案
您需要从 Azure 获取 SendGrid UserId 和 Key,然后使用以下代码发送电子邮件:
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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d5d6d7f4cccdce9ad7dbd9" rel="noreferrer noopener nofollow">[email protected]</a>", "Abc Xyz");
myMessage.Subject = emailSubject;
myMessage.Text = emailBody;
// Create credentials, specifying your user name and password. (Use SendGrid UserId & Password
var credentials = new NetworkCredential("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="24455e5156417b5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c64455e5156410a474b49" rel="noreferrer noopener nofollow">[email protected]</a>", "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;
}
}
更多信息您可以引用以下链接http://sendgrid.com/docs/Code_Examples/csharp.html
关于email - 如何使用 SendGrid 在 Microsoft Azure 中发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124675/