Home / Admin / WP Mail SMTP: Don’t Save Outlook Emails to Sent Items
Duplicate Snippet

Embed Snippet on Your Site

WP Mail SMTP: Don’t Save Outlook Emails to Sent Items

Stops the WP Mail SMTP Outlook mailer (Microsoft 365) from saving a copy of every email sent from the website to the connected account's Sent Items folder. Only affects the Outlook mailer. Emails larger than 4 MB with attachments are still saved to Sent Items, because Microsoft sends those a different way.

Code Preview
php
<?php
 /**
 * WP Mail SMTP: stop the Outlook mailer from saving a copy of every
 * sent email to the Sent Items folder of the connected Microsoft 365 account.
 *
 * Note: emails larger than 4 MB with attachments are sent a different way
 * by Microsoft and will still be saved to Sent Items.
 */
add_filter(
        'wp_mail_smtp_providers_mailer_get_body',
        function ( $body, $mailer ) {
                if ( $mailer === 'outlook' && is_array( $body ) ) {
                        $body['saveToSentItems'] = false;
                }
                return $body;
        },
        10,
        2
);

Comments

Add a Comment