尝试在Azure的VM ubuntu中使用SendGrid发送电子邮件时出错

时间:2019-02-21 18:00:12

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

SendGrid Azure 我有一台2年前在azure中使用Ubuntu创建的VM,在其中可以毫无问题地发送电子邮件至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";
 }

1 个答案:

答案 0 :(得分:0)

由于您引用的第一个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/

相关问题