How to override EmailMan class function ?

I want to override EmailMan class function. For that I have created file in custom/Extension/application/Ext/Include/EmailMan_SendGrid.php whose content is as below.

<?php [code] $objectList['EmailMan'] = 'EmailMan'; $beanList['EmailMan'] = 'CustomEmailMan'; $beanFiles['CustomEmailMan'] = 'custom/modules/EmailMan/EmailMan.php'; [/code] Then I have created file custom/modules/EmailMan/EmailMan.php and whose content is as below. [code] <?php $GLOBALS['log']->fatal("ABCD"); class CustomEmailMan extends EmailMan { public function sendEmail(SugarPHPMailer $mail, $save_emails = 1, $testmode = false) { $GLOBALS['log']->fatal("Lokesh"); return false; } } [/code] File is called because it log ABCD in suitecrm.log but Lokesh is not logged. And already it called default method sendEmail. Help me to shortout this issue.

Maybe something simpler can work to change those arrays, for example:

include/modules_override.php:

$beanFiles['EmailMan'] = 'custom/modules/EmailMan/EmailMan.php';

The code that is using this is:

https://github.com/salesagility/SuiteCRM/blob/master/modules/EmailMan/EmailMan.php#L881-L887

EDIT: disregard this post, this is not right, and won’t work

Overriding Bean file may not help because Old Bean file may be called directly many places.

What exactly do you want to do?

I want to override to send email from sendgrid. So I want to override this class method.

Not possible to use a new action using custom controller.php?

How to use custom controller. So you have any documentation link ?

Should be this one!

https://docs.suitecrm.com/developer/controllers/

Should custom controller override existing class method ?

Because I want to override that, as I asked in question. Please look the file modules/EmailMan/EmailMan.php and in this file I have to override sendEmail method.

Try adding a stack backtrace dumped on to the logs, from inside “SendEmail” function, to see where it is being called from.

Use ideas from here:
https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/22472-easy-trick-for-troubleshooting-suitecrm

Once you understand how it is being called, it’s easier to figure out how to hook up your function override.

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