Skip to content

Instantly share code, notes, and snippets.

@hitxiang
Last active July 9, 2019 09:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hitxiang/39f2d336acf7d5685a5a6866319b824e to your computer and use it in GitHub Desktop.
Save hitxiang/39f2d336acf7d5685a5a6866319b824e to your computer and use it in GitHub Desktop.
setup postfix in centos 6
#From cespi/php-5.3:cli-latest
From centos:centos6.9
RUN yum update -y \
&& yum install -y postfix cyrus-sasl-plain php rsyslog
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
#COPY .env /.env
# 1, export environment variables
# 2, run entrypoint.sh
# 3, start rsyslog
# 4, start postfix
#ENTRYPOINT ["entrypoint.sh"]
#!/bin/bash -eu
# https://docs.aws.amazon.com/ja_jp/ses/latest/DeveloperGuide/postfix.html#send-email-postfix-prereqs
# Postfix setting
sed -i '/relayhost/d' /etc/postfix/main.cf
sed -i 's/inet_protocols = all/inet_protocols = ipv4/g' /etc/postfix/main.cf
cat << EOT >> /etc/postfix/main.cf
relayhost = [$SMTP_ENDPOINT]:$SMTP_PORT
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
EOT
echo "[$SMTP_ENDPOINT]:$SMTP_PORT $SMTP_USER_NAME:$SMTP_PASSWORD" > /etc/postfix/sasl_passwd
postmap hash:/etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt'
#cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
## PHP setting
#cat << EOT > `php -i | grep php.ini | awk '{print $NF}'`/php.ini
#[Date]
#date.timezone = "Asia/Tokyo"
#[mail function]
#sendmail_path = /usr/sbin/sendmail -t -i
#EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment