wpexpertsio / Post-SMTP

Next generation SMTP mailer plugin for WordPress. Trusted by over 300,000 sites by WPExperts.io
https://wordpress.org/plugins/post-smtp/
55 stars 28 forks source link

Block outgoing email when not from whitelisted domain #42

Closed jb510 closed 5 years ago

jb510 commented 5 years ago

Most of us have some kind of MailCatcher running on our local development boxes. Some staging environments have something similar.

All of these prevent SMTP email from being sent, but API connections to services like SendGrid often bypass those email blocks.

It would be ideal if Post SMTP had a simple setting: Only send email from this domain: domain.com

Then if/when a site was copied to domain.test or domain.local, or domain.dev.cc, or domaindev.com, domain.staging.wpengine.com or whatever... Post SMTP would know to log the email, but not to actually process it for sending though SMTP or APIs.

NielsdeBlaauw commented 5 years ago

Thanks for the suggestion @jb510

You can use define( 'POST_SMTP_RUN_MODE', 'log_only' ); in your wp-config.php file to disallow a dev or staging environment from actually sending emails.

This is 'safer' than using the method you described, as you are likely to do a search-replace when migrating the database from production to the other environment.

Does the POST_SMTP_RUN_MODE config value provide the feature you need?

jb510 commented 5 years ago

Thank you for the tip! It sounds like it will.

I didn’t know that was built in, but with it I can certainly write my own functions to conditionally set it based on the url if needed.