Hello @crossy,
Thank you for trying FluentSMTP and for appreciating the free Amazon SES integration!
Regarding triggering webhooks on delivery failures, there isn’t a built-in feature for that directly within the plugin dashboard at this time. However, you can achieve this with a bit of custom coding.
The following WordPress action hooks might be very useful for this:
fluentmail_email_sending_failed
fluentmail_email_sending_failed_no_fallback
You can use these hooks to trigger your desired webhook. Essentially, you’d create a custom function that is executed whenever one of these hooks is fired. Inside that function, you’d then implement the logic to send the webhook to your desired endpoint.
Here’s a basic outline of what the code might look like (this is just an example and would need to be adapted to your specific webhook needs):
add_action( 'fluentmail_email_sending_failed', 'my_fluentmail_webhook_handler', 10, 2 );
function my_fluentmail_webhook_handler( $mail, $error_message ) {
// $mail contains the WP_Mail object with email details (to, from, subject, body, etc.)
// $error_message contains the error message related to the failure.
$webhook_url = 'YOUR_WEBHOOK_URL'; // Replace with your webhook URL
$payload = array(
'to' => $mail->get_recipients(),
'subject' => $mail->get_subject(),
'error_message' => $error_message,
// Add any other relevant data you want to send
);
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $payload,
'cookies' => array()
);
$response = wp_remote_post( $webhook_url, $args );
if ( is_wp_error( $response ) ) {
error_log( 'Webhook failed: ' . $response->get_error_message() );
} else {
// You can log the webhook response here if needed
//error_log( 'Webhook response: ' . wp_remote_retrieve_body( $response ) );
}
}
Important Notes:
- Replace
YOUR_WEBHOOK_URL with the actual URL where you want to send the webhook.
- This is a simplified example. You’ll likely need to customize the
$payload array to include the specific data you want to send to your webhook endpoint.
- Add this code to your theme’s
functions.php file (child theme is recommended) or a custom plugin.
- Properly handle errors and exceptions in your webhook handler.
- Consider security implications and implement appropriate measures if you are sending sensitive information.
I hope this provides a good starting point!