email - 如何使用 SendGrid 在 Microsoft Azure 中发送电子邮件

标签 email azure sendgrid

在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/

相关文章:

html - 创建简单的 html 电子邮件需要哪些 html 标记?

azure - 如何检查流量管理器是否全局存在

Azure Sendgrid 丢失了

azure - 使用 BeginUploadFromStream 时 Blob 不存在

asp.net - 如何调试 Azure 500 内部服务器错误

azure - 尝试在 azure 服务器上创建 sendgrid 帐户时出现问题

outlook-addin - 如何在 Microsoft Outlook 2010 中指定外发电子邮件的 X header

email - 使用 `Gmail SMTP` 从我的 Web 应用程序发送 `mail`。但是收到身份验证错误

php - OpenCart - 不发送电子邮件(通知或联系页面)

php - 电子邮件内容中单词内的随机空格