How To Set Up Postfix For Testing Code

Skip to first unread message


Feb 23, 2022, 2:44:19 PMFeb 23
I need a "dummy" SMTP server to test if some code can send emails correctly and I'd like to use Postfix for this.

Emails (obviously) shouldn't be sent to the recipient list. I only need them saved in a file somewhere so I can read the file and make assertions with a unit test framework: from, to, subject, content etc.

Additionally, I'd need to identify any Postfix-generated errors - no recipient address specified, invalid email address formats etc. I expect the unit test framework can find these by reading Postfix logs, so that should be straightforward.

But any tips how to configure Postfix to dump outgoing emails to file(s) instead of sending? Perhaps I need another piece of software working with Postfix to do this?

Even just a general outline would be a great help. I can probably figure out the details.

Thanks :)

Johann Beretta

Feb 25, 2022, 2:43:30 AMFeb 25
I'd say the easiest way would be to simply not allow postfix to reach
the rest of the internet. I.e. block port 25.

The messages will go into the queue and be stuck there for whatever
amount of time has been configured before they "time out".

They'll still be on disk in one of the postfix working folders.

:/var/spool/postfix$ ls
active corrupt deferred etc hold lib pid public trace
bounce defer dev flush incoming maildrop private saved usr

and you will be able to examine them.
Reply all
Reply to author
0 new messages