How to extend the XenForo_Mail class

Sadik B

Well-known member
I noticed the load_class_mail event listener. Assuming that it works similar to how controllers are extended, I created a code event listener MyAddon_Listener::load_class_mail

PHP:
public static function load_class_mail($class, array &$extend)
    {
        if ($class == 'XenForo_Mail')
        {
            $extend[] = 'MyAddon_Mail';
        }
    }

However the class MyAddon_Mail is not extending the send() method. Am I doing this wrong? How can one go about extending the XenForo_Mail::send() method?

Thanks...
 
I haven't actually done this but if it does in fact work the same way as the controllers, you'd make a new file with

PHP:
Class myaddon_mail extends XFCP_myaddon_mail
{
 Public function send()
 {
   $parent = parent::send(); // so you can get any data returned by the parent.
 }
}
 
I haven't actually done this but if it does in fact work the same way as the controllers, you'd make a new file with

PHP:
Class myaddon_mail extends XFCP_myaddon_mail
{
Public function send()
{
   $parent = parent::send(); // so you can get any data returned by the parent.
}
}

Thanks for replying. Yeah, this is what I did and this does not work...
 
From what I can tell, load_class_mail should work, especially if XenForo_Mail is instantiated using the XenForo_Mail::create method.

If you're certain it's not working, you might want to try the load_class event instead.

One or other should work fine.
 
Nopes... Still not working...

PHP:
public static function load_class($class, array &$extend)
    {
        if ($class == 'XenForo_Mail')
        {
            $extend[] = 'MyAddon_Mail';
        }
    }

And in library/MyAddon/Mail.php

PHP:
class MyAddon_Mail extends XFCP_MyAddon_Mail
{
    public function send($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
    {
        $userModel = XenForo_Model::create('XenForo_Model_User');
        $user = $userModel->getUserByEmail($toEmail);

        if (!empty($user))
        {
            $tempArr = explode(',', $user['secondary_group_ids']);

            if (!in_array('17', $tempArr))
            {
                return false;
            }
            else
                return parent::send($toEmail, $toName, $headers, $fromEmail, $fromName, $returnPath);
        }
    }
}

The send() method is not being overridden. I tried a simple vardump, no luck either. Does anyone has a working example of extending the XenForo_Mail class?
 
Any ideas why the above code is not overriding XenForo_Mail @Chris Deeming ?

And @Rigel Kentaurus

I saw you posted this,

I ended up overriding the sendMail() method to call my own setupTransport() method. It is working for me now, and I have a "pool" of email users to send from

It would be an immense help if you could show how you did this and which event listener you used?

Thanks guys.... :)
 
I, too, find myself in the position of needing to extend the Mail class/functions. Can anyone help with this? Has anyone in this thread figured it out by now?
 
Top Bottom