Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

This is a simple PostFix setup for only sending outbound e-mails and forwarding e-mails sent to root.

Note: For G-Mail you may need to allow un-secure Applications.

Ubuntu :


sudo su
apt-get update && apt-get install -y postfix postfix-pcre mailutils 

CentOS :

yum install -y postfix mailx cyrus-sasl cyrus-sasl-plain

Configure:

Note: You need to copy into a text editor and uncomment the desired Relay Host

cat << 'EOL' >/etc/postfix/main.cf
#
# PostFix Config
 
##Modify Below [HOSTNAME] & [DOMAIN]
myhostname = [HOSTNAME]
mydomain = [DOMAIN.COM/NET/ORG]
 
##UnComment Relay
# G-Mail
#relayhost = [smtp.gmail.com]:587
# Comcast Residential
#relayhost = [smtp.comcast.net]:587
# Comcast Business
#relayhost = [smtp.hmc1.comcast.net]:587
smtpd_banner = $myhostname ESMTP $mail_name
biff = no
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
canonical_maps = hash:/etc/postfix/canonical
mydestination = $myhostname.$mydomain $myhostname localhost
sender_canonical_maps = static:$myhostname@$mydomain
EOL

Note: CentOS Requires the following


mkdir /etc/postfix/sasl


G-Mail

cat << EOL >/etc/postfix/sasl/sasl_passwd
[smtp.gmail.com]:587    username@gmail.com:password
EOL

Comcast Residential

cat << EOL >/etc/postfix/sasl/sasl_passwd
[smtp.comcast.net]:587    username@comcast.net:password
EOL

Comcast Business

cat << EOL >/etc/postfix/sasl/sasl_passwd
[smtp.hmc1.comcast.net]:587    username@domain.com:password
EOL

Configure TO: Field AKA Root Alias Mapping (Change user@example.com)

cat << EOL >/etc/aliases
postmaster:    root
root: user@example.com
trash: /tmp/mail.trash
EOL
cat << EOL >/etc/postfix/canonical
root     user@domain.com
EOL

Configure PostMap DB for PASSWD & Alias

chmod 600 /etc/postfix/sasl/sasl_passwd
chown postfix:postfix /etc/postfix/ -R
postmap /etc/postfix/sasl/sasl_passwd
postmap /etc/postfix/canonical
newaliases
service postfix restart

Ubuntu

tail -f /var/log/mail.log

CentOS

tail -f /var/log/maillog

In a NEW TERMINAL

Test Mailing via CLI

echo "PostFix Setup Test" | mail -s "Postfix has been configured for $HOSTNAME to send e-mails" freesoftwareservers@gmail.com

Test Root Forward

echo "PostFix Setup Test" | mail -s "Root Forward - Postfix has been configured for $HOSTNAME to forward roots e-mails to this address" root

Note: I had trouble once with FROM Field and this solution was a permanent Fix:

cat << EOL >/etc/postfix/header_checks
/^From:[[:space:]]+(.*)/ REPLACE From: "$HOSTNAME" <Admin@FreeSoftwareServers.com>
EOL
sudo su
cd /etc/postfix
postmap header_checks
postconf -e 'smtp_header_checks = regexp:/etc/postfix/header_checks'
/etc/init.d/postfix reload

https://wiki.4psa.com/display/KB/How+to+change+the+From+header+for+messages+sent+by+Postfix

  • No labels