News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

stop SMF from sending mail to specific users

Started by dataspiller, December 10, 2016, 02:53:11 AM

Previous topic - Next topic

dataspiller

I'm looking to get SMF to not send an email to any one who is part of a certain member group - used to mainly deal with accounts who keep bouncing back emails for what ever reason.

The problem I am having is finding out exactly how to intercept the email before it is sent, and to stop that outgoing email if needed.

I was hoping to use the integration hook integrate_outgoing_email, which the wiki page on integration hooks says would include the recipient(s) the mail is being sent to.

How ever looking at the source code for the function sendmail in Subs-post.php where the integration hook is called, it looks like the recipient is never passed to the integration hook function calls, either directly via variable reference, or indirectly by it being added to a header before the integration call.

Is there an other way to intercept the email? Or will I just need to modify the core code and throw in a simple function call to my custom code in the sendmail function?


I'm using SMF 2.0.12

Shambles

Did you try dumping out the $headers var to see its content? As you say, according to the wiki the recipients should be listed in there

Quote$headers - the headers (which includes who it's to, who it's from, date, return path and other things)

dataspiller

I added "log_error('Start Header - ' . $headers . ' Finish header','critical',__FILE__,__LINE__);" to just before the hook functions get called.


So my code snip would be:


// Construct the mail headers...
$headers = 'From: "' . $from_name . '" <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>' . $line_break;
$headers .= $from !== null ? 'Reply-To: <' . $from . '>' . $line_break : '';
$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;

if ($message_id !== null && empty($modSettings['mail_no_message_id']))
$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
$headers .= 'X-Mailer: SMF' . $line_break;

log_error('Start Header - ' . $headers . ' Finish header','critical',__FILE__,__LINE__);

// Pass this to the integration before we start modifying the output -- it'll make it easier later.
if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers)), true))
return false;

// Save the original message...
$orig_message = $message;



More header work is done after the hook call.


Error log now reports (path masked just to be safe_:

Apply Filter: Only show the errors with the same message
Start header - From: "Xian Gamers" <******@xiangamers.com>
Return-Path: *****@xiangamers.com
Date: Sat, 10 Dec 2016 08:24:56 -0000
X-Mailer: SMF
finish header
Apply Filter: Only show the errors from this file File: %SMFINSTALL%/Sources/Subs-Post.php
Line: 689



I don't actually have a function being called by the hook yet.


Seth

Shambles

Hmm.. yeah. Looks like the wiki is incorrect.

You'll have to inspect the $to_array I guess (should be able to do this within the hook?)

dataspiller

Just tested the hook integration call and as I suspected - the recipient is not passed to on the hook integration call.

So either the wiki is right, and the devs forgot to pass the recipient onto the integration call, or it is behaving as intended, and the wiki is wrong.


I'm just going to throw a function call some where in the sendmail function to do what I want to do.

It would be a simple fix to add &$to_array to the integration hook call but then any future mods that I may add will throw errors because of not dealing with the pass $to_array.


Shambles

Could your hook code not globalise the $to_array and modify it in isolation, thereby leaving the integration call intact?

The wiki description is still incorrect, imho.

dataspiller

If by globalize you mean do a global $to_array in my hook code, that doesn't work.


If I'm going to modify any core code, I'll just include my own code instead of changing something else. Less likely to mess things up, easiest to remember what I did if I have to replace it due to an upgrade.


thanks for your help


Seth

Advertisement: