Action Hooks – Post SMTP

Action Hooks

Estimated reading: 3 minutes 1507 views

This documentation is intended for developers and contains PHP code examples. If you’re not familiar with PHP or WordPress development, we recommend avoiding custom code changes to prevent performance issues with your site.

The following code snippets are native to the Post SMTP plugin.

All of the following code snippets can be added to your theme’s functions.php file or a custom plugin if you prefer keeping modifications separate from theme updates.

Note: Ensure the Post SMTP plugin is installed and activated on your WordPress site before proceeding.

post_smtp_on_success

The code snippet will fire after an email has been successfully sent.

  • Parameters:
    • $log – Email log object.
    • $postmanMessage – Email message object.
    • $transcript – Transcript of the email session.
    • $transport – Transport method used.
add_action( 'post_smtp_on_success', 'handle_email_success', 10, 4 );

/**
 * Triggered after Post SMTP successfully sends an email.
 *
 * @param object         $log            Email log object.
 * @param PostmanMessage $postmanMessage Email message object.
 * @param string         $transcript     Full SMTP session transcript.
 * @param string         $transport      Transport method used (e.g., 'smtp', 'gmail').
 */
function handle_email_success( $log, $postmanMessage, $transcript, $transport ) {
    error_log( sprintf(
        'Email #%d sent via %s. Recipient: %s',
        $log->ID,
        $transport,
        implode( ',', (array) $postmanMessage->getToAddress() )
    ) );
}

post_smtp_on_failed

The code snippet will fire when an email fails to send.

  • Parameters:
    • $log – Email log object.
    • $postmanMessage – Email message object.
    • $transcript – Transcript of the email session.
    • $transport – Transport method used.
    • $error_message – Error message from the exception.
add_action( 'post_smtp_on_failed', 'handle_email_failure', 10, 5 );

function handle_email_failure( $log, $message, $transcript, $transport, $error_message ) {
    error_log( 'Email failed using ' . $transport . ': ' . $error_message );
}

postman_delete_logs_successfully

The code snippet will fire after email logs are successfully deleted.

add_action( 'postman_delete_logs_successfully', 'after_logs_deleted', 10, 1 );

function after_logs_deleted( $args ) {
    // Example: Log the deletion action
    error_log( 'Post SMTP logs deleted. Args: ' . print_r( $args, true ) );

    // Optional: Notify site admin or external system
}

post_smtp_after_email_log_saved

The code snippet will fire after an email log entry is successfully saved.

add_action( 'post_smtp_after_email_log_saved', 'handle_custom_log_action' );

function handle_custom_log_action( $log_id ) {
    // Example: Record the log ID or notify an admin
    error_log( 'A new email log was saved. Log ID: ' . $log_id );
} 

Looking to customize more aspects of Post SMTP? Browse our Filter Hooks and Microsoft Office 356 snippets guides for further enhancements.

Share this Doc

Action Hooks

Or copy link

CONTENTS
👋 Having issues sending email
in WordPress? Lets Chat 👇
Scroll to Top