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 sasl2-bin libsasl2-modules
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 # Outlook #relayhost = [smtp.office365.com]:587 # Entrust #relayhost = [mail.eternatec.com]:587 smtpd_banner = $myhostname ESMTP $mail_name biff = no append_dot_mydomain = no readme_directory = no smtpd_use_tls=yes #smtp_tls_security_level = may smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key 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 = +sender_canonical_maps inet_interfaces = all inet_protocols = ipv4 alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = $mydomain #canonical_maps = hash:/etc/postfix/sender_canonical mydestination = $myhostname.$mydomain $myhostname localhost sender_canonical_maps = static:$myhostname@$mydomain #sender_canonical_maps = regexp:/etc/postfix/sender_canonical 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 chmod 600 /etc/postfix/sasl/sasl_passwd postmap /etc/postfix/sasl/sasl_passwd
Comcast Residential
cat << EOL >/etc/postfix/sasl/sasl_passwd [smtp.comcast.net]:587 username@comcast.net:password EOL chmod 600 /etc/postfix/sasl/sasl_passwd postmap /etc/postfix/sasl/sasl_passwd
Comcast Business
cat << EOL >/etc/postfix/sasl/sasl_passwd [smtp.hmc1.comcast.net]:587 username@domain.com:password EOL chmod 600 /etc/postfix/sasl/sasl_passwd postmap /etc/postfix/sasl/sasl_passwd
Outlook:
cat << EOL >/etc/postfix/sasl/sasl_passwd [smtp.office365.com]:587 username@domain.com:password EOL chmod 600 /etc/postfix/sasl/sasl_passwd postmap /etc/postfix/sasl/sasl_passwd
Entrust:
cat << EOL >/etc/postfix/sasl/sasl_passwd [mail.eternatec.com]:587 username@domain.com:password EOL chmod 600 /etc/postfix/sasl/sasl_passwd postmap /etc/postfix/sasl/sasl_passwd
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 newaliases
cat << 'EOL' >/etc/postfix/sender_canonical root user@domain.com EOL postmap /etc/postfix/sender_canonical
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