[Solved] Add custom variable to all outgoing email

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Badhon_raj
Registered User
Posts: 103
Joined: Wed Jan 04, 2012 6:33 pm

[Solved] Add custom variable to all outgoing email

Post by Badhon_raj » Wed Oct 11, 2017 3:20 am

Hi,
I need to add custom variable to all outgoing emails from a board.
Can you please point out how to intercept any outgoing mail and modify it before sending out?
I couldn't find any relative event in the event list.
I might be mistaken, so please correct me if I'm wrong.

Any kind of help toward the solution will be greatly appreciated.
I'm ok with core file edit.
It doesn't have to be modular.

P.S I was wondering if there is any single file where I can do the editing, or do I need to edit various files for different kind of emails, e.g. welcome email, birthday mail, newtopic mail etc.
Last edited by Badhon_raj on Thu Oct 12, 2017 5:16 am, edited 1 time in total.

rxu
Extensions Development Team
Posts: 2752
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Add custom variable to all outgoing email

Post by rxu » Thu Oct 12, 2017 4:49 am

In common, you need handling class messenger in includes/functions_messenger.php which has methods to assign template variables to emails.
But it's rather impossible to add custom variable to all emails as you'd need to put additional placeholder to all email template files. It can be added by editing ones though (this way will never be validated by the Team).

Badhon_raj
Registered User
Posts: 103
Joined: Wed Jan 04, 2012 6:33 pm

Re: Add custom variable to all outgoing email

Post by Badhon_raj » Thu Oct 12, 2017 5:15 am

rxu wrote:
Thu Oct 12, 2017 4:49 am
In common, you need handling class messenger in includes/functions_messenger.php which has methods to assign template variables to emails.
But it's rather impossible to add custom variable to all emails as you'd need to put additional placeholder to all email template files. It can be added by editing ones though (this way will never be validated by the Team).
Thanks for your reply :) , I've already figured it out though.
I was about to update this topic.

Rather than editing the email template files, I appended my variable to $this->msg add around line #300

Code: Select all

$this->msg = $this->msg . $my_variable;

rxu
Extensions Development Team
Posts: 2752
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: [Solved] Add custom variable to all outgoing email

Post by rxu » Thu Oct 12, 2017 5:34 am

Well, that's also an invasion to the core files which is not allowed in extensions system, but whatever.

rxu
Extensions Development Team
Posts: 2752
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: [Solved] Add custom variable to all outgoing email

Post by rxu » Thu Oct 12, 2017 5:35 am

Instead, you could use core.modify_notification_message event to appeng the message nicely ;)

Badhon_raj
Registered User
Posts: 103
Joined: Wed Jan 04, 2012 6:33 pm

Re: [Solved] Add custom variable to all outgoing email

Post by Badhon_raj » Thu Oct 12, 2017 5:38 am

rxu wrote:
Thu Oct 12, 2017 5:34 am
Well, that's also an invasion to the core files which is not allowed in extensions system, but whatever.
Yes, I found no way to modify email content via an extension.
There's an event that allows modification of only the headers, but not the body.

Badhon_raj
Registered User
Posts: 103
Joined: Wed Jan 04, 2012 6:33 pm

Re: [Solved] Add custom variable to all outgoing email

Post by Badhon_raj » Thu Oct 12, 2017 5:39 am

rxu wrote:
Thu Oct 12, 2017 5:35 am
Instead, you could use core.modify_notification_message event to appeng the message nicely ;)
I must have missed this, I'll look into it.
Thanks a lot for mentioning it.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: HJW and 6 guests