POSTFIX: Emails received locally, but aliases won't forward

Currently I have installed, and configured postfix. If I send a email to let's say 'admin@XYZ.com' I receive the email(s) locally on the server. I would like to get these said emails to 'XYZ' to forward to my gmail account. Currently I have tried adding aliases through postfix to no avail.

Current postfix/main.cf

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
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_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = mail.XYZ.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mail.XYZ.com,  XYZ.com, localhost.XYZ.com, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
virtual_alias_maps = hash:/etc/postfix/virtual
home_mailbox = mail/

Current postfix/virtual

admin@XYZ.com  gaccount@gmail.com

Thanks for the help!

7 Replies

Put that config file in between [ code ] and [ /code ] (remove the spaces) to make it easier to read. It's hard to tell it apart from your actual post.

If you're not using a database with Postfix, add your forwarding rules to /etc/aliases in the form of:

admin@xyc.com: gaccount@gmail.com

the run the newaliases command. If it still doesn't work, restart Postfix.

If you are using a database, you'll need to add your aliases to whichever database/table you're using for aliases, then restart Postfix (and maybe Dovecot if you're using it for authentication).

Thanks for the reply Piki,

I just sent out a test email and didn't receive anything, but from the logs it looks like it went ok?

Jul 31 17:45:38 noble postfix/cleanup[4196]: 43493501B9: message-id= <canhcpysozozcpg+xe8nunokemgmtz3kzavo27mi2jt2ofnqvgw@mail.gmail.com>Jul 31 17:45:38 noble postfix/local[4197]: 2CE42501B7: to=<xyz@domain.com>, relay=local, delay=0.14, delays=0.13/0.01/0/0, dsn=2.0.0, status=sent (forwarded as 43493501B9)
Jul 31 17:45:38 noble postfix/qmgr[4175]: 43493501B9: from=<gaccount@gmail.com>, size=1849, nrcpt=1 (queue active)
Jul 31 17:45:38 noble postfix/qmgr[4175]: 2CE42501B7: removed
Jul 31 17:45:38 noble postfix/smtpd[4191]: disconnect from mail-oa0-f52.google.com[209.85.219.52]
Jul 31 17:45:38 noble postfix/smtp[4198]: 43493501B9: to=<gaccount@gmail.com>, orig_to=<xyz@domain.com>, relay=gmail-smtp-in.l.google.com[173.194.74.27]:25, delay=0.58, delays=0/0.01/0.09/0.48, dsn=2.0.0, status=sent (250 2.0.0 OK 1375307138 a12si143361qeg.101 - gsmtp)
Jul 31 17:45:38 noble postfix/qmgr[4175]: 43493501B9: removed</xyz@domain.com></gaccount@gmail.com></gaccount@gmail.com></xyz@domain.com></canhcpysozozcpg+xe8nunokemgmtz3kzavo27mi2jt2ofnqvgw@mail.gmail.com> 

Sometimes there's a delay, especially when sending to or receiving from the larger email providers. It shouldn't take more than a few minutes.

If you don't receive it in your Gmail account soon, double check your log. Also double check your /etc/aliases file for typos.

If you forward messages from a Gmail account back to Gmail, they won't show up in your Gmail inbox. Gmail recognizes that it originated from your account and won't show it in the inbox.

Test by sending a message to admin@XYZ.com from another mail provider.

Edit: as a general rule, you should also run newaliases after editing a Postfix alias file. This generates the db file (which is what Postfix actually uses) from the text file.

So tried just tried using a different account, which again just let me get the email locally (still nothing forwarded). Checked the mail.log and this is what I'm getting:

Aug  1 10:46:34 noble postfix/cleanup[6478]: warning: database /etc/postfix/virtual.db is older than source file /etc/postfix/virtual
Aug  1 10:46:34 noble postfix/pickup[6450]: CA3B0501B9: uid=33 from= <www-data>Aug  1 10:46:34 noble postfix/trivial-rewrite[6479]: warning: database /etc/postfix/virtual.db is older than source file /etc/postfix/virtual
Aug  1 10:46:34 noble postfix/cleanup[6478]: CA3B0501B9: message-id=<20130801144634.CA3B0501B9@mail.xyz.com>
Aug  1 10:46:34 noble postfix/qmgr[4175]: CA3B0501B9: from=<www-data@mail.xyz.com>, size=414, nrcpt=1 (queue active)
Aug  1 10:46:35 noble postfix/smtp[6480]: CA3B0501B9: to=<gaccount@gmail.com>, relay=gmail-smtp-in.l.google.com[2607:f8b0:400d:c02::1b]:25, delay=0.55, delays=0.01/0.01/0.06/0.46, dsn=2.0.0, status=sent (250 2.0.0 OK 1375368395 6si1750106qat.86 - gsmtp)
Aug  1 10:46:35 noble postfix/qmgr[4175]: CA3B0501B9: removed
Aug  1 11:03:27 noble postfix/master[2395]: daemon started -- version 2.9.6, configuration /etc/postfix</gaccount@gmail.com></www-data@mail.xyz.com></www-data> 

Found the issue.. Sadly forgot to point my (mail) MX subdomain to my A record.

@starboy:

Aug  1 10:46:34 noble postfix/cleanup[6478]: warning: database /etc/postfix/virtual.db is older than source file /etc/postfix/virtual

This indicates that your changes to /etc/postfix/virtual are not being used and you need to run postmap hash:/etc/postfix/virtual to generate an updated virtual.db file.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct