mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
8.95k stars 1.17k forks source link

send mail from phpfpm-mailcow container #208

Closed chaosbunker closed 7 years ago

chaosbunker commented 7 years ago

I have added a simple website with a php contact form that normally sends emails via the mail() function ... since there is no MTA in the phpfpm container this does not work.

how can I use sendmail of the postfix container to send mail from that form (or at some point from a wordpress blog)?

I first tried by customizing the Dockerfile of the phpfpm container and added ssmtp and told ssmtp to use postfix-mailcow as the mailhub, mail comes through to the postfix container but can't be processed. this is the error message:

Apr 18 11:01:09 mx postfix/smtpd[331]: connect from mailcowdockerized_php-fpm-mailcow_1.mailcowdockerized_mailcow-network[172.22.1.3] Apr 18 11:01:09 mx postfix/smtpd[331]: Anonymous TLS connection established from mailcowdockerized_php-fpm-mailcow_1.mailcowdockerized_mailcow-network[172.22.1.3]: TLSv1 with cipher AES128-SHA (128/128 bits) Apr 18 11:01:09 mx postfix/smtpd[331]: fatal: host/service dovecot/10001 not found: Name or service not known Apr 18 11:01:10 mx postfix/master[320]: warning: process /usr/lib/postfix/sbin/smtpd pid 331 exit status 1 Apr 18 11:01:10 mx postfix/master[320]: warning: /usr/lib/postfix/sbin/smtpd: bad command startup -- throttling

i also tried adding and using sendmail instead of ssmtp but it fails because it does not have a FQDN in /etc/hosts and adding the mailcow hostname to the phpfpm container via docker-compose.yml but it didn't seem to work

but anyway, i ideally want to send mail through the postfix container directly. is there an elegant solution?

chaosbunker commented 7 years ago

Ok, I figured it out:-) in case anyone wants to know how to do this, this is how i did it (or look in my fork, branch phpfpm-and-sendmail)

If anyone knows a better way of doing this or if my way is in any way bad practice or possibly causing issues, please let me know! For me this is working fine though:-)

  1. Customize and build Dockerfile of php-fpm-mailcow with sendmail and gettext (the latter to get envsubst)
  2. add files data/conf/phpfpm/php-mail.conf (to set sendmail_path) and data/conf/phpfpm/sendmail.mc.template (to do the envsubst). To make sure sendmail uses the mailcow hostname the sendmail.mc template has this line added in the end define(`SMART_HOST',`${MAILCOW_HOSTNAME}')
  3. In docker-compose.yml changed for container php-fpm-mailcow:
php-fpm-mailcow:
[...]
  command: /bin/bash -c "envsubst < /etc/mail/sendmail.mc.template > /etc/mail/sendmail.mc &&
           m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf &&
           service sendmail restart &&
           php-fpm -d date.timezone=${TZ}"

  volumes:
        - ./data/conf/phpfpm/php-mail.conf:/usr/local/etc/php/conf.d/mail.ini:ro
        - ./data/conf/phpfpm/sendmail.mc.template:/etc/mail/sendmail.mc.template:ro

  hostname: ${MAILCOW_HOSTNAME}
[...]