Stop postfix from sending email for testing

This applies to CentOS 6. You may want to do this when testing some code and you’re not sure if it is going to send emails or not.

Edit /etc/postfix/main.cf

Add following lines at the bottom:

myhostname = localhost
mydomain = localdomain
inet_interfaces = $myhostname, localhost
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks_style = host
default_transport = error:outside mail is not deliverable

Save the file then run the following commands (as root)

postfix upgrade-configuration
postfix check
newaliases

Test by mailing something to yourself

mail username@example.com

Check that it just gets put in the root mailbox

mail

Enter the number of the email you want to read and it appears, d to delete it, z to return to the list, q to quit.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA - answer the question below to prove you are human *

This site uses Akismet to reduce spam. Learn how your comment data is processed.