I struggled a LOT — way too much — fixing an issue with my SSMTP install so I decided to share the solution here.

I got multiple instances of php inside docker containers. Every instance should be able to send emails, but instead of installing a mail server in each docker, I've set them to use SSMTP to relay emails. SSMTP will relay emails to an exim docker (namshi/smtp) which will send emails.

(n * [PHP -> SSMTP]) -> EXIM

I had to set /etc/ssmtp/revaliases and /etc/ssmtp/ssmtp.conf according to their docs, but it worked only when I was sending emails through root, but not with PHP which is working through www-data.

I renamed the linked dockers so php instances and ssmtp call them by "mailhub".


SSMTP was NOT giving any hint or nothing except Cannot open mailhub:25. After HOURS reading SSMTP source code, trying every possible steps to reproduce what SSMTP was doing, I finally found it...

When using www-data, /etc/ssmtp was not reachable because of file permissions. SSMTP is SILENT about this and never inform you that it uses its default configuration instead of an unreachable config file.

All I had to do to fix that was : chmod 777 /etc/ssmtp /etc/ssmtp/*

NOTE : my config files do not contain any password and I don't really care about security in this particular case, but any body who is concerned by these issues should not use 777 but may be 640 instead.

Useful commands to test your config:

  • sudo -u root ssmtp -v my.own.email@gmail.com < mail.txt
  • sudo -u www-data ssmtp -v my.own.email@gmail.com < mail.txt
  • /usr/sbin/ssmtp -v my.own.email@gmail.com < mail.txt

Content of mail.txt :

From: my.company@my.domain.com

To: my.own.email@gmail.com

Subject: test email

test text

  • I don't know if this will fix my very similar problem, but thank you for thinking of other developers after solving your problem! – Glitcher Apr 29 '18 at 22:24

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.