【问题标题】:Error trying to send email with SendGrid in a VM ubuntu in Azure尝试在 Azure 的 VM ubuntu 中使用 SendGrid 发送电子邮件时出错
【发布时间】:2019-02-21 18:00:11
【问题描述】:

SendGrid Azure 我有一个带有 Ubuntu 的虚拟机,它是我 2 年前在 azure 中创建的,我可以在其中毫无问题地发送电子邮件 throw SendGrind。

现在我用 ubuntu 创建了另一个 VM,我复制了我在另一个服务器中的相同代码,但没有任何效果。我收到 500 错误。 如果我评论下一行,错误就消失了,但我不知道为什么会出现问题:

 $response = $sendgrid->send($email);

我不记得我是否需要在服务器中安装一些东西,希望你有一些想法。

require("../sendgrid-php/sendgrid-php.php");
//If not using Composer, uncomment the above line
$email = new \SendGrid\Mail\Mail();
$email->setFrom("xxxxx@gmail.com", "Example User");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("xxxxxxx@gmail.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent("text/html", "<strong>and easy to do anywhere, even with PHP</strong>");
$sendgrid = new \SendGrid(getenv('the-key'));
try {
    $response = $sendgrid->send($email);
    print $response->statusCode(). "\n";
    print_r($response->headers());
    print $response->body() . "\n";
 } catch (Exception $e) {
     echo 'Caught exception: ',  $e->getMessage(), "\n";
 }

【问题讨论】:

    标签: php azure ubuntu sendgrid sendgrid-api-v3


    【解决方案1】:

    由于您引用的第一个 VM 已有两年历史,您可能正在使用标准端口 25 与 SendGrid 通信。从 2017 年 11 月 15 日开始,从虚拟机 (VM) 直接向外部域(例如 Outlook.com、gmail.com)发送出站电子邮件将仅适用于某些订阅类型。对于大多数新订阅,使用 TCP 端口 25(主要用于未经身份验证的电子邮件传递)的出站 SMTP 连接将被阻止(更多详细信息如下)。

    有关选项的更多详细信息:

    https://blogs.msdn.microsoft.com/mast/2017/11/15/enhanced-azure-security-for-sending-emails-november-2017-update/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 2021-08-10
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 2018-05-16
      相关资源
      最近更新 更多