Postfix/mysql forward and deliver

Is there a way to set up postfix to forward but also deliver? After following the Postfix with Courier and MySQL on Ubuntu 9.10 guide I added values into the forwardings table and tried sending mail. The mail is being properly forwarded.

However, I have some forwardings that are like username@mydomain.com -> username@gmail.com, and in this case, I want the mail to be forwarded to gmail but also be delivered locally, but right now it just forwards and does not retain a copy. How can I get that to happen?

4 Replies

I've never used it, but it seems like this might help:

http://www.postfix.org/ADDRESS_REWRITIN … l#auto_bcc">http://www.postfix.org/ADDRESSREWRITINGREADME.html#auto_bcc

Or if procmail is being used to deliver local mail, you could put something like the following in ~/.procmailrc for the user in question:

:0Hc
* !^X-Loop: YOURGMAILNAME@gmail.com
{
  # Avoid potential mail loops
  :0 fwh
  | formail -A"X-Loop: YOURGMAILNAME@gmail.com"

  # Forward to the other account
  :0
  ! YOURGMAILNAME@gmail.com
}

Disclaimer: I haven't tested this, stole it from here.

This is simple to do with Postfix natively – no need to rely upon any add-ons or external apps such as procmail.

The method used depends upon whether original the destination address is a real system user or not (assuming a fairly default Postfix environment).

If the local recipient user is a real system account on your server, modify your aliases file (default: /etc/aliases), and add an entry for the user.

Say the user's system/shell account is 'someuser', and you want a copy sent to the user on the local machine, and a copy sent to someaccount@gmail.com, you would specify the following:

someuser:                 someuser someaccount@gmail.com

Save your changes, close the file, and update db file used by Postfix by issuing the following command:

newaliases

If the recipient address is not an actual system account, but instead is just a virtual user locally using a virtual domain, the easiest way to do this is to rely upon the virtual file – the default is /etc/postfix/virtual, but is whatever file is declared by the virtualaliasmaps value in your main.cf

Say the recipient email address is someuser@somedomain.com, which is then routed to a local virtual alias on your server of acct@domain2.com, and you want that local user to receive a copy and a copy to also be sent to acct2@gmail.com. Your /etc/postfix/virtual changes would look like this:

someuser@somedomain.com               acct@domain2.com acct2@gmail.com

All one line. Save your changes, close the file, and then issue the command:

postmap /etc/postfix/virtual

to update the db file used by Postfix, using whatever file you have configured Postfix to use and just edited.

This of course assumes that domain2.com was setup as a local virtual mailbox domain, is NOT listed as a virtualaliasdomain, and that somedomain.com is defined in either virtualaliasdomain or in mydestination parameters in main.cf so that Postfix will know to accept mail authoritatively for those domains.

In other words, this all assumes you've properly configured your Postfix MTA otherwise. Be sure you run 'newaliases' and/or 'postmap' as root, or if you're using a Distro that gimps the root account, run it with root permissions using 'sudo'.

@skavoovie:

If the recipient address is not an actual system account, but instead is just a virtual user locally using a virtual domain, the easiest way to do this is to rely upon the virtual file – the default is /etc/postfix/virtual, but is whatever file is declared by the virtualaliasmaps value in your main.cf
The OP was using mysql lookups for virtualaliasmaps, so I wasn't sure if they could have multiple entries (I don't use mysql).

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