Send email on testing docker container with php and sendmail

后端 未结 2 987
广开言路
广开言路 2021-02-04 19:26

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 w

2条回答
  •  甜味超标
    2021-02-04 19:57

    If it says:

    "Package 'ssmtp' has no installation candidate"

    You can use msmtp instead.

    Add the following to your dockerfile

    # sendmail config
    #################
    ARG SMTP_PASSWORD=not_provided
    # install
    RUN apt-get install -q -y msmtp mailutils
    # config
    COPY msmtprc /etc/msmtprc
    RUN chmod 600 /etc/msmtprc
    RUN chown www-data:www-data /etc/msmtprc
    ARG SMTP_PASSWORD=not_provided
    RUN sed -i "s|YourAwesomeStr0ngP4zzw0rd|$SMTP_PASSWORD|g" /etc/msmtprc
    # Set up php sendmail config
    RUN echo "sendmail_path=/usr/bin/msmtp -t" >> /etc/php/7.3/apache2/conf.d/php-sendmail.ini
    

    Add a msmtprc file to your docker build context:

    account default
    host mail.yoursmtpserver.com
    port 587
    tls on
    tls_starttls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt
    tls_certcheck on
    auth on
    user my@mail.com
    password "YourAwesomeStr0ngP4zzw0rd"
    from "my@mail.com"
    logfile /var/log/msmtp.log
    

    note: Some changes were made in order to make it work with my particular setup (branching FROM eboraas/apache-php). This applies particularily to the lines:

    • ARG SMTP_PASSWORD=not_provided
    • RUN chown www-data:www-data /etc/msmtprc
    • RUN sed -i "s|YourAwesomeStr0ngP4zzw0rd|$SMTP_PASSWORD |g" /etc/msmtprc
    • RUN echo "sendmail_path=/usr/bin/msmtp -t" >> /etc/php/7.3/apache2/conf.d/php-sendmail.ini

    You may need to adapt paths, passwords and so on to fit your needs. Keep in mind to set the SMTP_PASSWORD build argument from environment (e.g. SMTP_PASSWORD= docker-compose build) if you want to use this solution straight away.

    Useful resources:

    • https://wiki.debian.org/msmtp
    • https://owendavies.net/articles/setting-up-msmtp/
    • https://wiki.archlinux.org/index.php/msmtp#Send_mail_with_PHP_using_msmtp
    • linux msmtp configuration sends from shell but fails from PHP/apache

提交回复
热议问题