简体   繁体   中英

How to receive Slack notification on Mailgun?

Is there a way easily to send a notification to Slack from Mailgun. 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

Well I found a simple answer.

On Mailgun: Create a new webhook to point to a PHP file, like: mailgun.php

Inside add a simple Slack Webhook call:

<?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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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