File: //wordpress/mu-plugins/mail.php
<?php
/*
Plugin Name: Enable SMTP
Plugin URI: https://github.com/Automattic
Version: 0.1
Author: <a href="http://wordpress.com/">Atomic</a>
Description: Atomic SMTP plugin
*/
/**
* Plugin to make wp_mail use SMTP
*/
function atomic_enableSMTP( $phpmailer ) {
if ( 'cli' == php_sapi_name() ) {
$smtp_username = DOMAIN_NAME;
} else {
$smtp_username = $_SERVER['HTTP_HOST'];
}
$phpmailer->Host = '127.0.0.1';
$phpmailer->Port = AT_SMTP_PORT;
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $smtp_username;
$phpmailer->Password = AT_SMTP_PASS;
$phpmailer->isSMTP();
}
function atomic_add_mail_tracking_header( $phpmailer ) {
$trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
foreach ( $trace as $idx => $call ) {
if ( $idx < 5 ) {
continue;
}
if ( in_array( $call['function'], array(
'do_action',
'apply_filters',
'do_action_ref_array',
__FUNCTION__,
'wp_mail',
'html_email_end',
'html_email_simple_send',
'wp_html_mail',
) ) ) {
continue;
}
if ( isset( $call['class'] ) ) {
if ( in_array( $call['class'], array( 'WordPressMailer' ) ) ) {
continue;
}
if ( is_subclass_of( $call['class'], 'WordPressMailer' ) ) {
continue;
}
$caller = "{$call['class']}->{$call['function']}";
break;
}
$caller = $call['function'];
break;
}
$raw_data = base64_encode( $caller );
$cron = 0;
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
$cron = 1;
}
$ja3_hash = '-';
if ( isset( $_SERVER['HTTP_X_JA3_HASH'] ) ) {
$ja3_hash = $_SERVER['HTTP_X_JA3_HASH'];
}
$phpmailer->AddCustomHeader( sprintf( 'X-Atomic-Tracking: %d:%d:%s:%d:%d:%d:%d:%s',
ATOMIC_SITE_ID,
ATOMIC_CLIENT_ID,
$raw_data,
get_current_blog_id(),
get_the_ID(),
get_current_user_id(),
$cron,
$ja3_hash
) );
$phpmailer->AddCustomHeader( sprintf( 'X-Atomic-Caller: %s', $caller ) );
}
add_action( 'phpmailer_init', 'atomic_enableSMTP' );
add_action( 'phpmailer_init', 'atomic_add_mail_tracking_header' );