Postfix

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail. It is intended as a fast, easier-to-administer, and secure alternative to the widely-used Sendmail MTA.

HOWTO: Virtual Domains Address Redirecting Users Aliases
/etc/postfix/main.cf: virtual_alias_domains = example.com fish.com fooey.com virtual_alias_maps = hash:/etc/postfix/virtual /etc/postfix/virtual: postmaster@example.com postmaster info@example.com      joe sales@fish.com        jane sales@fooey.com       jeff # Uncomment entry below to implement a catch-all address # @example.com        jim

postmap /etc/postfix/virtual postfix reload

Thanks - http://www.postfix.org/VIRTUAL_README.html

HOWTO: Log Information (Subject)
http://askubuntu.com/questions/245299/postfix-logging

HOWTO: Per User Relay Transport Mapping
sudo postconf -e "transport_maps = hash:/etc/postfix/transport"

/etc/postfix/transport

domain1.com            local: user1@domain2.com      smtp:smart.host1.com:25 domain2.com            local: user1@domain3.com      smtp:smart.host1.com:25 user2@domain3.com      smtp:smart.host2.com:25 domain3.com            local: *                      smtp:outbound.smarthost.com:25

Please note that transport_maps override relayhost parameter. However, you can have a * smtp:outbound.smarthost.com:25 line in your transport file as shown above.

sudo postmap /etc/postfix/transport sudo postfix reload

Thanks - http://superuser.com/questions/718803/postfix-relay-mail-to-smart-host-for-specifc-users

HOWTO: Configure Per Domain Transport Mapping
EXAMPLES In order  to  deliver internal mail directly, while using a mail relay for all other mail, specify a null entry for internal destinations (do       not change the delivery transport or the nexthop information) and spec- ify a wildcard for all other destinations. my.domain   : .my.domain  : *        smtp:outbound-relay.my.domain

/etc/postfix/main.cf

mynetworks = 127.0.0.1/8 192.168.1.0/24 smtpd_recipient_restrictions = permit_mynetworks check_sender_access hash:/etc/postfix/sender_access reject_unauth_destination transport_maps = hash:/etc/postfix/transport

/etc/postfix/sender_access

mydomain.com OK localhost OK localhost.localdomain OK

/etc/postfix/transport

localhost : localhost.localdomain : mydomain.com : thatdomain.com smtp:[smtp.thatdomain.com]  <-- this is where the magic happens :) * smtp:[auth.smtp.1and1.co.uk]:587

Thanks - http://www.postfix.org/transport.5.html

Thanks - https://www.howtoforge.com/community/threads/postfix-relay-one-domain-to-smarthost-a-all-else-to-smarthost-b.62955/

Old - http://serverfault.com/questions/257637/postfix-to-relay-mails-to-other-smtp-for-particular-domain

HOWTO: Configure Multiple ISP Client SMTP Authentication
http://www.cyberciti.biz/faq/postfix-multiple-isp-accounts-smarthost-smtp-client/

HOWTO: Add Various Options To The Config File
Security

sudo -i postconf -e "myorigin = example.com" postconf -e "myhostname=server1.example.com" postconf -e "relay_domains = example.com, example2.com, example3.com"

Thanks - https://wiki.debian.org/Postfix

HOWTO: Completely Remove Postfix From Debian Or Ubuntu
sudo aptitude remove postfix* --purge

FAQ
http://www.cise.ufl.edu/~jnw/SysAdminsp01/Lectures/postfix-html/faq.html

HOWTO: Fix: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Add the following line to /etc/postfix/main.cf...

alias_maps = hash:/etc/aliases

Run the alias mapping tool...

sudo newaliases

Restart Postfix...

sudo service postfix restart

HOWTO: Use Dovecot LDA
http://wiki2.dovecot.org/LDA/Postfix

nano /etc/postfix/main.cf mailbox_command = /usr/lib/dovecot/dovecot-lda -f "$SENDER" -a "$RECIPIENT"

Main Email Hostname
nano /etc/mailname server1.domain.com

Disable IPv6
Edit /etc/postfix/main.cf and put the following...

inet_protocols = ipv4

Bind Postfix Mail Server To Localhost or Specific IP Address Only
Edit /etc/postfix/main.cf and put the following...

inet_interfaces = 127.0.0.1

Configure For SMTP AUTHentication In Ubuntu Linux
It would be nice to be able to send email messages from your Ubuntu Linux computer, but most ISPs will not accept them, because of authentication restrictions. These instructions give them what they want...

Change to the Postfix directory...

cd /etc/postfix/

Configure main configuration file... sudo nano main.cf

Either add or edit the following with your required settings...

smtp_generic_maps = hash:/etc/postfix/generic smtp_sasl_auth_enable = yes relayhost = [my.smtp.host.co.uk] smtp_sasl_password_maps = hash:/etc/postfix/sasl_password smtp_sasl_security_options = noanonymous

Create the SASL password file...

sudo nano sasl_password [my.smtp.host.co.uk] me@myemailaccount.com:passW0rD

Lock down permissions...

sudo chmod 0600 sasl_password

Hash the file...

sudo postmap hash:sasl_password

Create the Postfix generic maps file...

sudo nano generic root@myhostname.localdomain me@myemailaccount.com user1@myhostname.localdomain me@myemailaccount.com user2@myhostname.localdomain me@myemailaccount.com

Hash the file...

sudo postmap hash:generic

Copy the supporting files to the Postfix working directory...

sudo cp -av /etc/hosts /var/spool/postfix/etc/ sudo cp -av /etc/services /var/spool/postfix/etc/ sudo cp -av /etc/localtime /var/spool/postfix/etc/ sudo cp -av /etc/resolv.conf /var/spool/postfix/etc/

Create the header checks file for later (with MailScanner)...

sudo touch /etc/postfix/header_checks Start Postfix...

sudo postfix start

Install mailutils and mutt...

sudo aptitude install -y mailutils mutt

Send test email message...

mail me@myemailaccount.com Subject: test Cc: message CTRL+D

Configure For SMTP AUTHentication With STARTTLS Security Non Standard Port In Ubuntu Linux
sudo nano /etc/postfix/main.cf          relayhost = [mail.domain.com]:587 smtp_tls_security_level = may sudo nano /etc/postfix/sasl_password [mail.domain.com]:587 username@domain.com:MyPasswOrd sudo postmap hash:/etc/postfix/sasl_password sudo service postfix restart

Check The Mail Queue
mailq

Flush The Mail Queue
sudo postfix flush

Delete A Single Message In The Mail Queue
mailq (to get ID of message) sudo postsuper -d GH123459706X

Delete All Messages In The Mail Queue
sudo postsuper -d ALL

Reload Postfix Configuration
sudo postfix reload

Restart Postfix
sudo postfix restart

or

sudo service postfix restart

ERROR: Name service error for xxx.com: Host not found, try again
If you get this error in /var/log/mail/info it might be because your /var/spool/postfix/etc/resolv.conf is wrong. If you look in /var/log/mail/warnings and sees

warning: /var/spool/postfix/etc/resolv.conf and /etc/resolv.conf differ you should copy /etc/resolv.conf to /var/spool/postfix/etc/.

The error comes because you run postfix as chroot and postfix can then only see files in /var/spool/postfix/. During install postfix takes a copy of /etc/resolv.conf and place it in its own directory.

There could be more errors than that. Check /var/log/mail/warnings and /var/log/mail/errors and make sure you have verified all files. In case of more trouble run the command postfix check.

You could also get error messages like:

postfix/postfix-script: warning: /var/spool/postfix/etc/localtime and /etc/localtime differ postfix/postfix-script: warning: /var/spool/postfix/etc/services and /etc/services differ Which implies that /etc/localtime and /etc/services should be copied. Before doing anything check what the difference of the files is.

FIX: postdrop: warning: unable to look up public/pickup: No such file or directory
/etc/init.d/sendmail stop update-rc.d -f sendmail remove update-rc.d postfix defaults /etc/init.d/postfix start