Introduction
This article explains how to configure integrations in Gravity SMTP to use provider-specific parameters to enable GDPR-compliant routing or other requirements.
Why use custom API parameters with email integrations
Some email services allow routing email through specific IP pools or adding custom flags to API requests. Using the http_request_args WordPress hook allows developers to modify outgoing request parameters to meet compliance or infrastructure requirements.
How to configure integrations using a filter
All Gravity SMTP integrations (excepting PHP Mailer) that send mail through the WordPress HTTP API utilize wp_safe_remote_post, enabling developers to modify request arguments using the http_request_args filter. This approach works for SendGrid, SparkPost, Mailgun, and other supported APIs.
Examples
Set SendGrid IP Pool used for sending
add_filter( 'http_request_args', function( $parsed_args, $url ) {
if ( str_contains( $url, 'api.sendgrid.com/v3/mail/send' ) ) {
$parsed_args['ip_pool_name'] = 'EU Traffic';
}
return $parsed_args;
}, 10, 2 );
Set Postmark message stream used for sending
add_filter( 'http_request_args', function( $parsed_args, $url ) {
if ( str_contains( $url, 'api.postmarkapp.com/email' ) ) {
$parsed_args['MessageStream'] = 'notifications';
}
return $parsed_args;
}, 10, 2 );
You can adapt this pattern for other integrations by checking the corresponding API endpoint and adding or adjusting parameters as needed (for example, setting transactional flags, region routing, or specific options provided by your SMTP email service).