简体   繁体   English

如何在 Mailgun 上接收 Slack 通知?

[英]How to receive Slack notification on Mailgun?

Is there a way easily to send a notification to Slack from Mailgun.有没有一种方法可以轻松地从 Mailgun 向 Slack 发送通知。 Is it possible?可能吗?

The resource I find somewhat useful is this, but seems too complicated: http://obem.be/2017/09/08/working-with-mailgun-webhooks.html我觉得有点用的资源是这个,但似乎太复杂了: http://obem.be/2017/09/08/working-with-mailgun-webhooks.html

Well I found a simple answer.好吧,我找到了一个简单的答案。

On Mailgun: Create a new webhook to point to a PHP file, like: mailgun.php在 Mailgun 上:创建一个新的 webhook 以指向 PHP 文件,例如: mailgun.php

Inside add a simple Slack Webhook call:在里面添加一个简单的 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);

And that's it.就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM