emails not to be saved
-
Hi.
I would like some emails not to be saved, is it possible? Have you some exemples of hooks?
-
Hi @f14m07, currently this isn’t possible but adding a hook to cover this is a nice idea and would also handle some other edge-cases. I’ve added this as a feature request on our GitHub tracker, I’ll aim to roll this out in the next release. Not sure when that’ll be currently but I’ll message back here once it’s available.
I’m going to close this issue here as it’s much easier for me to organise this via GitHub ??
Cheers,
JamesHey @f14m07, just letting you know that this functionality has been released in v2.1.8 the hook you’ll need is
wp_mail_catcher_before_success_log_save
and the documentation can be found in the “Hooks and actions” section of the plugin page.Hi @wardee,
Thank you very much for your work, it will be a great help to me
Hi,
Some pb:I don’t find the filter hook wp_mail_catcher_before_success_log_save in the WPMC code.
Have you a short example with this hook please ?
Here is an example. Maybe there is better. This will not save the mail with subject XXXX or YYYY
<?php /************** * desactivate log mail by mailcatcher * ************ */ add_filter('wp_mail_catcher_before_success_log_save','my_mail_catch_filter'); function my_mail_catch_filter($transformedArgs){ if ($transformedArgs['subject']=='XXXXX' || $transformedArgs['subject']=='YYYYY'){ return false; } return $transformedArgs; }
Hi @f14m07, yes your example is correct. If a message is sent with a subject of either
XXXXX
orYYYYY
the log will not be saved. Otherwise it’ll proceed as normal.If you’d like more info then an idea would be to take a look at the unit tests for the hook. An example of which can be seen here. You probably couldn’t find references to the hook inside the code as all mentions are prefixed with a namespace. If you search the code for
_before_success_log_save
or_before_error_log_save
you should find them eg hereHope that helps!
Hi,
Many thanks to Fred17 for asking this very useful question !
But, as I’m probably missing a few neurons, I can’t manage to filter the logs of mails containing a very specific subject…
I’d like to avoid logging emails containing “Database Backup” as subject, but this code, placed in the functions.php of my child theme, doesn’t work:add_filter('wp_mail_catcher_before_success_log_save','my_mail_catch_filter'); function my_mail_catch_filter($transformedArgs){ if (str_contains($transformedArgs['subject'], "Database Backup")) { return false; } return $transformedArgs; }
I use php 8.1
I also tried strpos without success. In every case, if I click on resend, email is sent (that’s a good news), but this new mail is logged.Do you have an idea for solving my problem ?
Many thanks in advance !Best regards
Hi, I have an undesirable side effect.
I have several plugins that work on the emails sent by my site.
Easy WP SMTP, which makes sure that emails are sent by my host’s SMTP server.
WP HTML Mail – Email Template Designer which gives a unique template to all outgoing emails.
Mail logging – WP Mail Catcher, which keeps a record of all e-mails sent.
I added my code to the wp_mail_catcher_before_success_log_save hook.
Since then, emails that are filtered according to a specific subject are not stored in the database and are sent to the recipients, but the unique template is not applied to them.
In other words, the WP HTML Mail plugin fulfils its role for emails that are stored but not for others.
Do you have any idea what causes this difference?Hi,
What if you try to change the order of plugin which are loaded ?
Whith “Plugin Organizer”, you can easily do it. Perhaps “WP HTML Mail” plugin will fulfill its role until end if it is executed last ?
Yes, I’ll look into it. But it’s strange that for stored emails there’s also the template, whereas for those that aren’t stored the template is forgotten?
I tested the Plugin Organizer plugin on my Local installation. I swapped the loading order of WP Mail Catcher (now loaded first) and WP HTML Mail (now loaded after).
But this doesn’t change the problem of the template not being used when the mails are not stored.Hey guys, @joy0114 your code snippet (pasted below) looks fine to me, I’ve tested this locally and it correctly doesn’t log emails that have “Database Backup” in their description. The only thing I could imagine that could be catching you out is that it’s case sensitive – so “database backup” would still be logged.
add_filter('wp_mail_catcher_before_success_log_save','my_mail_catch_filter');
function my_mail_catch_filter($transformedArgs){
if (str_contains($transformedArgs['subject'], "Database Backup")) {
return false;
}
return $transformedArgs;
}@f14m07, I’ve looked into your issue and I’ve found a bug. I’ll release a fix this weekend and will reply here once it’s out
Hi @f14m07, I’ve just released version 2.1.9 which should solve your issue. Let me know, if it’s still a problem ??
Hi @wardee, the new release resolve my issue. All is fine now. Thanks for your work.
Hi JWardee,
Thanks for your answer.
I solved my issue:I think the white space was causing the issue. So, I tried strcmp for comparing strings, and with this, it works perfectly !
add_filter('wp_mail_catcher_before_success_log_save','my_mail_catch_filter'); function my_mail_catch_filter($transformedArgs){ $sujet_a_detecter="Database Backup"; $sujet_mail=$transformedArgs['subject']; if (strcmp($sujet_mail, $sujet_a_detecter) == 0) { return false; } return $transformedArgs; }
Thank you very much for your plugin: so useful !
Best regards
- The topic ‘emails not to be saved’ is closed to new replies.