How to override EmailMan class function ?

I know this is an old thread, but I just had to solve this problem and I’d like to leave the answer here for future reference:

Create this file (and any missing subdirectories):
custom/Extension/application/Ext/Include/CustomEmailMan.php

With these contents:

<?php
$customBeanList['EmailMan'] = 'CustomEmailMan';
$customObjectList['EmailMan'] = 'CustomEmailMan';
$customBeanFiles['EmailMan'] = 'custom/modules/EmailMan/CustomEmailMan.php';
?>

Then in custom/modules/EmailMan/CustomEmailMan.php, you can make something like this, overriding the functions you need to customize:

<?php

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}

require_once 'modules/EmailMan/EmailMan.php';

class CustomEmailMan extends EmailMan {

    public function sendEmail(SugarPHPMailer $mail, $save_emails = 1, $testmode = false) {

...

    }

}
3 Likes