0

I want to create a module which alters the recipients of all outgoing emails so that in dev environment email are only sent to developers or testers and not to real users. So the recipients should be altered before sending the email in defined circumstances.

I tried hook_civicrm_alterMailingRecipients() but this hooks gets called when I create a mailing and add recipients to the corresponding field. This is not what I need - I don't want to alter the recipients on creation of a mass/bulk mailing.

Is there any way to alter recipients for all outgoing email (indiviual emails, mailings, system mails - if there are any) in any way? In Drupal we have hook_mail_alter() which allows to alter just everything in an email and which I used for this functionality already.

2

2 Answers 2

2

I would use the alterMailParams hook and replace the to, cc, bcc in $params

2
  • Thank you for this hint - I did not see this hook. It seems to do exactly what I want... I'll test it! May 9 at 6:02
  • Thank you again... with this hook it works!!! May 11 at 11:20
0

You probably want to connect your dev environment to something like mailtrap. That way you'll be able to see the emails in an inbox. The alternative is to set all emails to write to the database instead, theres a setting to do that.

2
  • I'd like to avoid something like this as my solution would assure that the e-mails would not be sent no matter if a developer has locally installed a tool like mailtrap. Writing the e-mails to the database is no alternative as it is not possible to test the e-mails in real e-mail clients. May 9 at 6:05
  • Thanks for raising this Tobias - I am looking at exactly this issue. We cannot have a 'dev' first approach (e.g. I use MailHog on my local Docker dev environment) beacuse we need ordinary users to UAT and see the emails in the various clients they use themselves. I'll check out that hook.
    – ChumKui
    May 12 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.