• I am using SureMail to send WordPress emails via AWS SES. I need to implement a one-to-one mapping between visible From addresses and SES verified envelope senders.

    For example: Visible From SES Verified MAIL FROM

    newsletter@sub.example.com => newsletter@verified.sub.example.com

    contact@example.com => contact@verified.example.com

    notify@example.com => notify@verified.example.com

    I want the visible From address to remain friendly for recipients, while the SES MAIL FROM / Return-Path uses the verified subdomain address (as above), because AWS SES requires verified senders for envelope addresses.

    My issue is that my existing WordPress wp_mail and phpmailer_init filters work in logs, but SureMail overrides the envelope sender, so the mapping does not take effect in actual outgoing emails.

    Could you please provide:

    1. The exact filter or action hook in SureMail that allows me to modify the SES envelope sender (MAIL FROM) before sending.
    2. Any guidance or example on how to implement this mapping properly in SureMail.

    For reference:

    • WordPress version: 6.8.3
    • SureMail version: 1.9.0

    Thank you very much for your help!

    Example anonymized PHP snippet for SureMail:

    <?php
    /**
     * Map friendly visible From → SES verified MAIL FROM for SureMail
     * Place in: wp-content/mu-plugins/fc-ses-suremail-map.php
     */
    
    add_filter('suremail_pre_send_email', function($email) {
    
        // One-to-one mapping: visible From → SES verified envelope sender
        $map = [
            'newsletter@sub.example.com' => 'newsletter@verified.sub.example.com',
            'contact@example.com'         => 'contact@verified.example.com',
            'notify@example.com'          => 'notify@verified.example.com',
        ];
    
        // Get the visible From email
        $from = strtolower(trim($email['from'] ?? ''));
    
        // Apply mapping if exists
        if (isset($map[$from])) {
            $email['envelope_from'] = $map[$from]; // sets actual SES MAIL FROM / Return-Path
            error_log("SureMail SES MAP: {$from} → {$map[$from]}");
        } else {
            error_log("SureMail SES MAP: No mapping for {$from}");
        }
    
        return $email;
    }, 20);
    

    • This topic was modified 1 week, 5 days ago by unbent.
Viewing 1 replies (of 1 total)
  • Plugin Support Avinash Kumar Sharma

    (@avi1020p)

    Hello @unbent ,

    Our dev team reviewed the scenario, and they’ve prepared a code snippet that may help you achieve the setup you need.

    <?php
    /**
    * Map friendly visible From → SES verified envelope sender (MAIL FROM / Return-Path) for SureMail + AWS SES
    * Prerequisites:
    * - In SES connection: Force From Email = No; Return Path = No
    * Place in: wp-content/mu-plugins/ses-envelope-map.php
    */

    add_filter( 'suremails_send_email', function ( $allow ) {
    // Early exit if blocked.
    if ( ! $allow ) {
    return false;
    }

    // Get the PHPMailer instance.
    if ( ! class_exists( 'PHPMailer\\PHPMailer\\PHPMailer' ) ) {
    require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
    }
    $phpmailer = \SureMails\Inc\ConnectionManager::instance()->get_phpmailer();

    // One-to-one mapping: visible From → verified envelope sender.
    $map = [
    'newsletter@sub.example.com' => 'newsletter@verified.sub.example.com',
    'contact@example.com' => 'contact@verified.example.com',
    'notify@example.com' => 'notify@verified.example.com',
    ];

    // Get the visible From email (lowercase for matching).
    $visible_from = strtolower( trim( $phpmailer->From ?? '' ) );

    // Apply mapping if exists.
    if ( isset( $map[ $visible_from ] ) ) {
    $phpmailer->Sender = $map[ $visible_from ]; // Sets Return-Path header for SES MAIL FROM.
    error_log( "SureMail SES MAP: Visible From {$visible_from} → Envelope Sender {$map[$visible_from]}" );
    } else {
    error_log( "SureMail SES MAP: No mapping for visible From {$visible_from}; using default (ensure verified)" );
    }

    return true;
    }, 20 ); // Higher priority to run after any default callbacks.

    This snippet hasn’t been tested yet, so please try it on your setup and let us know how it goes.

    Best Regards,
    Avinash

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.