Postfix alias not working

I have postfix to send mail using gmail. I have aliases set but things aren't working right

if I send mail to someone at gmail.com it works

crontab with MAILTO=root sends mail via gmail relay to account

if I send mail to using mail -s "Test subject" <textfile, it works and sends via gmail relay (I get email at )

but if I send mail using mail -s "Test subject" root <textfile it tries to get gmail to send mail via gmail relay to root@mail even though alias is set to

hostname is mail
mailname is cmforester.com (/etc/mailname)

/etc/aliases:

postmaster:
root:
www-data:
clint: 

main.cf:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 0
mydestination = $myhostname, localhost
mydomain = cmforester.com
myhostname = mail.cmforester.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = $mydomain
readme_directory = no
recipient_delimiter = +
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_use_tls = yes
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
2

2 Answers

As suggested by NerdOfLinux I ran new aliases but it couldn't resolve "mail" so I looked in my hosts file and added "mail" next to "localhost" and that fixed it. I previously ran newaliases but then made some changes to the main.cf file and my hostname/domainname which I believe made my aliases become problematic

Editing:

/etc/postfix/main.cf

and changing:

myorigin = $mydomain

to:

myorigin = $myhostname

resolved the problem for me in that it:

  • Prevented the unexpected conversion of recipient root to root@$mydomain; and
  • Got my /etc/aliases forwarding working to the remote address I need

I won't pretend to be sure but my assumption is the following:

When a recipient without @somedomain.com is used ie. root, then postfix conceptually automatically appends @[myorigin parameter value]

if [myorigin parameter value] is identified as the local host, which $myhostname would be, then postfix knows it is destined for a local user and thus references /etc/aliases for the mapping.

Following the above logic, using $mydomain doesn't match the local host and is therefore assumed to be a remote address ie. root@$mydomain and so /etc/aliases gets ignored (as it is only applied to local server users)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like