如何在Mailgun永久失败时接收Slack通知?

问题描述 投票:0回答:1

有没有一种方法可以轻松地从Mailgun向Slack发送通知。可能吗?我找不到有关如何执行此操作的资源?我发现有些有用的资源是这个,但似乎太复杂了:http://obem.be/2017/09/08/working-with-mailgun-webhooks.html

php api webhooks slack mailgun
1个回答
0
投票

我找到一个简单的答案。

在Mailgun上:创建一个新的webhook指向一个php文件,例如:mailgun.php

在内部添加一个简单的Slack Webhook调用:

<?php

    // Constant to store your Slack URL
    define('SLACK_WEBHOOK', '{YOUR_SLACK_WEBHOOK_GOES_HERE}');
    // Make the message
    $newUserMsg = "🛑 Mailgun Failed Email";
    $message = array('payload' => json_encode(array('text' => $newUserMsg )));
    // Use curl to send your message
    $c = curl_init(SLACK_WEBHOOK);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, $message);
    curl_exec($c);
    curl_close($c);

就是这样。

© www.soinside.com 2019 - 2024. All rights reserved.