HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Is there an option to Send all email to a certain address IE developer mode

edited January 2020 in Vanilla 3.x Help

So because my Hosting provider where i am deving blocks all outgoing email to SMTP services I was wondering if there was a way to enable a dev mode so to speak that would allow sending of mail but it would all go to one email address. I don't want email to go out to public yet as i have imported my old data base and when i test replying to a discussion I don't want all the users to get emails.

Would be a cool feature to add if it does not exist!

Maybe it's time to create a plugin!!!


  • R_JR_J Ex-Fanboy Munich Admin

    I think the effort to write such a plugin would be quite high and the usage would be only a one time usage. Maybe there are better approaches? What about changing the mail addresses by SQL during testing phase?


    SET Email = 'User_' + UserID + '@mail.nu'

  • R_JR_J Ex-Fanboy Munich Admin
    edited January 2020

    Looking at the Gdn_Mailer again: you could quite easily write a plugin for your own purpose, but only for your own installtion because it would require a minimal change in one of Vanillas files. This is something that I normally do not advice. But in this case the change would be save and it should be reverted anyway when the work is done.

    If you take a look at the ActivityModel, you find this code:

                   $handled = false;
                   $this->EventArguments['Handled'] =& $handled;
                   if (count($this->validationResults()) > 0) {
                       return false;
                   if ($handled) {
                       // A plugin handled this activity so don't save it.
                       return $activity;

    Obviously there is a way for a plugin to stop further processing in this setup (even without understanding the code, the comment is a good hint)

    The Gdn_Email class doesn't have that. It only has this line:


    So if you edit this file and replace the line above with this construct:

           $handled = false;
           $this->EventArguments['Handled'] =& $handled;
           if ($handled) {
               // A plugin handled this mail so don't send it.
               return true;

    then you would be able to write a plugin which handles mails on its own way (e.g. by logging them to a table instead of sending them). Interested?

  • MrCaspanMrCaspan
    edited January 2020

    Thanks, this is a great entry point for a plugin. For now I might hack it and just using things like gmails ability to add onto an email address which is what i think you were alluding to in the first reply

    Example user@domain.com is my real email address but user+blablabla@domain.com will still be delivered to you because anything after the + is just ignored. I use it for things like my bank so I can tell email from them user+bankname@domain.com that way if I get spam on that address i know who sold my email address and if I get email saying they are form the bank I can quickly tell if it is legit because its to the proper address.

    Before the forum send out the email I could just stick some code in to take the email address it was going to send to (forumuser@theirdomain.com) and just flatten that to forumuser.theirdomain.com and stick that into my email address user+{$FlattenedEmail}@domain.com . This way all email would be addressed to me but I can see by the email address who it was supposed to go to!

    Simple hack to get around it because like you said don't need to do it often!

  • MrCaspanMrCaspan
    edited January 2020

    Forgot to ask any idea what file I would modify for all email? I'm assuming there is a function that all use to send out all email

    Edit: I think i just found it in /library/core/class.email.php let me poke around in there a bit!

  • This is kind of cool it seems like if debug mode is on it dumps to a log

            if ($this->isDebug() && $this->logger instanceof Psr\Log\LoggerInterface) {
                $payload = $this->PhpMailer->getSentMIMEMessage();
                    'Email Payload',
                    ['event' => 'Debug email',
                        'timestamp' => time(),
                        'userid' => Gdn::session()->UserID,
                        'username' => Gdn::session()->User->Name ?? 'anonymous',
                        'ip' => Gdn::request()->ipAddress(),
                        'method' => Gdn::request()->requestMethod(),
                        'domain' => rtrim(url('/', true), '/'),
                        'path' => Gdn::request()->path(),
                        'charset' => $this->PhpMailer->CharSet,
                        'contentType' => $this->PhpMailer->ContentType,
                        'from' => $this->PhpMailer->From,
                        'fromName' => $this->PhpMailer->FromName,
                        'sender' => $this->PhpMailer->Sender,
                        'subject' => $this->PhpMailer->Subject,
                        'body' => $this->PhpMailer->Body,
                        'payload' => $payload
  • MrCaspanMrCaspan
    edited January 2020

    looks like on line 434 the function 'to' i can modify the returns from

    return $this->to($recipientEmail, $recipientName);

    to be this

    return $this->to('myemail+' . $recipientName . '@doain.com', $recipientName);
  • R_JR_J Ex-Fanboy Munich Admin

    Changing files to achieve what you want is the dark side of the force, Luke!

    Instead of changing code to alter mail addresses, you really should change the mail addresses in the database. It's a one time action and more fail safe.

Sign In or Register to comment.