LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Postfix: relay mail for unknown user (https://www.linuxquestions.org/questions/linux-server-73/postfix-relay-mail-for-unknown-user-4175588637/)

goumba 09-03-2016 09:50 AM

Postfix: relay mail for unknown user
 
I don't know if relaying is the proper term, so forgive me.

I'm playing around with a home email server with virtual users, using postfix and dovecot.

What happens, is if I try to send an email to a virtual user that does not exist on the server, the email is rejected. What I would like to happen, is, if that user does not exist the email is passed on to another server.

Can this be done with postfix? I've looked at fallback_transport and fallback_relay as suggested by some duckduckgo-ing with no success.

I'd appreciate a nudge in the right direction, rather than the complete solution (I could always come back later if I can't get it on my own).

TIA

bathory 09-03-2016 10:55 AM

Quote:

What I would like to happen, is, if that user does not exist the email is passed on to another server.
Have a look at the luser_relay

goumba 09-04-2016 02:10 AM

I'd looked into luser_relay, and unless I'm misunderstanding, it's not what I want.

Unfortunately, re-reading my post, maybe it's not as clear as I'd like. Let me give an example in the hopes it is clear.

I have a virtual user setup, with a PostgreSQL back end. So, it has tables for domains, users and aliases as is typical. Username is the full email address (user@domain).

I send an email to "goumba@example.net". This user is not one of the users on this particular server. Postfix looks, finds example.net, but no such user on the server. The email is bounced.

What I would like it to do now is instead of bouncing that email, is submit it to another SMTP server (be it postfix or whatever), untouched, as if it was being submitted through that server initially. Same exact username, etc.

So,
Code:

email to goumba@example.org -> submit to postfix -> not found -> submit to smtp.exampleserver2.net
I hope I've better described my desire this time.

bathory 09-04-2016 10:43 AM

Quote:

What I would like it to do now is instead of bouncing that email, is submit it to another SMTP server (be it postfix or whatever), untouched, as if it was being submitted through that server initially. Same exact username, etc.
This is what luser_relay does. From this
Quote:

When the local(8) delivery agent finds that a message recipient does not exist, the message is normally returned to the sender ("user unknown"). Sometimes it is desirable to forward mail for non-existing recipients to another machine. For this purpose you can specify an alternative destination with the luser_relay configuration parameter.

goumba 09-05-2016 08:49 AM

Right, but I don't wish to transform the destination address in any form. In other words, no address rewriting.

So, say if I use

Code:

luser_relay = $user@exampleserver2.net
my username of xxxx@example.net becomes xxxx@exampleserver2.net. This is not what I want. I would like it to remain xxxx@example.net.

My use case is a little, err, odd: like I said this is just to get myself learning the postfix, dovecot, virtual user set up. I must admit, I hadn't posted this all earlier as I was avoiding describing the case as I was expecting, knowing people, rather than try to help, I would get a "WHY ARE YOU DOING THIS?" and no help.

Basically, here goes.

I set up postfix + dovecot for mail delivery locally and sending with virtual users. These users are actually a few of my off site email addresses, using getmail and postfix+lmtp to store copies locally. This works. The problem is actually because of a bit of a clash of domains.

I have an account, goumbaxx@gmail.com. A friend sends me an email to goumba@example.net. I wish to reply. His address is dudexx@gmail.com.

I send the email, and postfix looks in the pgSQL database of domains, finds gmail. Great. It should as it needs to do so to deliver MY mail locally.

It now looks up dudexx@gmail.com. BAM! Can't find it. Duh, not 'hosted' my on mail server. So, the email rightfully gets bounced.

gmail.com is not in mydestination, or other configuration directives in main.cf. The only place it is mentioned is in that pgSQL table.

What I would like to happen, just for the purposes of my use case, is to say 'ok, it's not here, now send it, exactly as is, to mail.example.net (not gmail's smtp, but that of my sending address) to be delivered. NO address writing or manipulation of the original email. I thought I understood fallback_transport to be a use for this along with local_recipient_maps = but it still bounces.

Relevant from log:
Code:

Sep  5 11:47:33 mail dovecot: lmtp(2461): Connect from local
Sep  5 11:47:33 mail postfix/lmtp[2632]: 386296C9599: to=<dudexx@gmail.com>, relay=mail[private/dovecot-lmtp], delay=0.41, delays=0.29/0.05/0/0.07, dsn=5.1.1, status=bounced (host mail[private/dovecot-lmtp] said: 550 5.1.1 <dudexx@gmail.com> User doesn't exist: dudexx@gmail.com (in reply to RCPT TO command))
Sep  5 11:47:33 mail dovecot: lmtp(2461): Disconnect from local: Successful quit
Sep  5 11:47:33 mail postfix/cleanup[2625]: 927EA6C95AA: message-id=<20160905154733.927EA6C95AA@mail>
Sep  5 11:47:33 mail postfix/bounce[2633]: 386296C9599: sender non-delivery notification: 927EA6C95AA
Sep  5 11:47:33 mail postfix/qmgr[2620]: 927EA6C95AA: from=<>, size=2126, nrcpt=1 (queue active)


bathory 09-05-2016 12:26 PM

Quote:

gmail.com is not in mydestination, or other configuration directives in main.cf. The only place it is mentioned is in that pgSQL table.
Ok I understand it's for learning purposes, but why put gmail.com into virtual domains. You should leave it apart, so postfix uses dns to find the correct MX host for gmail.com and deliver the email to it.
Re, your gmail account, you can setup forwarding to you local account.

Anyways, I've not tried anything similar, but perhaps you may give this a try.

Regards

goumba 09-05-2016 04:00 PM

Quote:

Originally Posted by bathory (Post 5601075)
Ok I understand it's for learning purposes, but why put gmail.com into virtual domains.

First thing I tried was removing it, and once I did postfix+lmtp stopped delivering mail locally to any affected account using that domain.

Quote:

Re, your gmail account, you can setup forwarding to you local account.
I know. The problem is not with my gmail account. It's with sending an email from the example.net account (which isn't really the domain name, the real domain is my personal domain) to a gmail account because of this set up.

Meh, thanks for your help. It seems this is something that can not be worked around. Thank you for your patience.

akiuni 09-17-2018 04:13 AM

Hello

(I know this is an old post, my answer is more about guys facing the same issue today)

Maybe you could think your problem in a different way, if you know the "local" users you can create a virtual alias for them a redirect the other to your gateway.

For example :

In main.cf, remove your destination domain (example.net) from mydestination and create a virtual aliases map :
Code:

myorigin = $mydomain
mydestination = localhost.local, localhost
virtual_alias_maps = hash:/etc/postfix/virtual

In your virtual alias map, redirect all your users to localhost :
Code:

cat > /etc/postfix/virtual <<_EOF_
user1    user1@localhost
user2    user2@localhost
_EOF_

create the db file and reload postfix :
Code:

postmap /etc/postfix/virtual
postfix reload

This way, all the emails to user1@example.net and user2@example.net will be delivered localy and those for user3@example.net will be sent to the relay host.

eemarc 06-06-2020 12:27 PM

Quote:

Originally Posted by akiuni (Post 5904290)
Hello

(I know this is an old post, my answer is more about guys facing the same issue today)

Maybe you could think your problem in a different way, if you know the "local" users you can create a virtual alias for them a redirect the other to your gateway.

For example :

In main.cf, remove your destination domain (example.net) from mydestination and create a virtual aliases map :
Code:

myorigin = $mydomain
mydestination = localhost.local, localhost
virtual_alias_maps = hash:/etc/postfix/virtual

In your virtual alias map, redirect all your users to localhost :
Code:

cat > /etc/postfix/virtual <<_EOF_
user1    user1@localhost
user2    user2@localhost
_EOF_

create the db file and reload postfix :
Code:

postmap /etc/postfix/virtual
postfix reload

This way, all the emails to user1@example.net and user2@example.net will be delivered localy and those for user3@example.net will be sent to the relay host.

Usually you use the full email address like "user1@example.net".

"example.net" must be specified in "main.cf" as virtual domain: "virtual_mailbox_domains = example.net", otherwise the virtual alias map would be ignored.

Then you have still the same problem.


All times are GMT -5. The time now is 01:06 PM.