Smart Email Routing
OM_Smart_Routing selects which SMTP connection to use per email send, with automatic failover.
How It Works
- The primary connection is used for all outgoing mail
- If the primary fails (
wp_mail_failedhook), OMailer switches to the backup connection for the remainder of the send batch - After the batch, the primary is reinstated
Routing Rules (Advanced)
Beyond primary/backup, you can define rules that route mail based on:
- From address — route transactional mail through a different SMTP than marketing
- Subject prefix — e.g.
[Order]→ SES, everything else → Gmail - Campaign tag — route campaigns tagged
bulkthrough a dedicated IP
Rules are evaluated in order; the first match wins. Falls back to the primary connection if no rule matches.
PHP API
php// Force a specific connection for the next wp_mail() call
OM_SMTP::set_connection( 'conn_id' );
// After custom send, release the override
OM_SMTP::clear_connection();
// Get the connection ID that would be resolved for current context
$conn_id = OM_SMTP::resolve_connection();
Hooks
php// Fired when failover activates
add_action( 'om_smtp_failover', function( string $failed_conn_id, string $backup_conn_id ) {
// log or alert
}, 10, 2 );
// Filter to override connection selection
add_filter( 'om_resolve_smtp_connection', function( string $conn_id, array $mail_data ): string {
// inspect $mail_data['to'], $mail_data['subject'], etc.
return $conn_id;
}, 10, 2 );