Send email on testing docker container with php and sendmail

ratm picture ratm · Nov 12, 2017 · Viewed 15.6k times · Source

I'm on ubuntu 16.04. I have a (testing) docker (docker-compose) container running php 5.6 and apache 2.4.

On the production platform (without docker) the mail is sent with sendmail.

How to send test email on docker container (with sendmail)?

Thanks in advance for responses.

Answer

ratm picture ratm · Nov 25, 2017

It works.

In Dockerfile :

# sendmail config
############################################

RUN apt-get install -q -y ssmtp mailutils

# root is the person who gets all mail for userids < 1000
RUN echo "[email protected]" >> /etc/ssmtp/ssmtp.conf

# Here is the gmail configuration (or change it to your private smtp server)
RUN echo "mailhub=smtp.gmail.com:587" >> /etc/ssmtp/ssmtp.conf
RUN echo "[email protected]" >> /etc/ssmtp/ssmtp.conf
RUN echo "AuthPass=yourGmailPass" >> /etc/ssmtp/ssmtp.conf

RUN echo "UseTLS=YES" >> /etc/ssmtp/ssmtp.conf
RUN echo "UseSTARTTLS=YES" >> /etc/ssmtp/ssmtp.conf


# Set up php sendmail config
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini

For testing inside php sendmail container :

echo "Un message de test" | mail -s "sujet de test" [email protected]

I succeed with the help of this two documents :