forwarding mail for a complete virtual domain to another mailserver?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
Hi,

I wonder if this can be achieved easily. I'm migrating from one server
to another, which includes migrating the postfix mailserver as well. I'm
hosting a number of virtual domains on the mail server. Naturally I want
to make the transition as smooth as possible.

I'm planning to migrate the virtual domains one by one - and I will also
have to face the fact that the update of the MX record for the domain
will take some time. Thus, for some time, mail will arrive an both the
old and new locations from various sources.

Therefore I'm thinking about a solution where I can tell the old mail
server to accept the mail for the specific virtual host, but to forward
it immediately to the new server. Thus, even if the mail goes to the old
server, it will land at it's new and correct location. Of course, this
should only be working for the duration of the transition period.

I was looking at the documentation here:
http://www.postfix.org/VIRTUAL_README.html where there is a catch-all
virtual domain forwarding configuration - but that would forward all
mail to a single mail account. What I'm looking for is to forward a
complete domain - that is, all mail destined for that domain to be
forwarded to a different server, with the same recipient e-mail address.

Is such a setup possible? If so, how?


Akos
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Magnus Bäck
On Thursday, July 30, 2009 at 10:35 CEST,
     Maróy Ã?kos <[hidden email]> wrote:

> I wonder if this can be achieved easily. I'm migrating from one server
> to another, which includes migrating the postfix mailserver as well.
> I'm hosting a number of virtual domains on the mail server. Naturally
> I want to make the transition as smooth as possible.
>
> I'm planning to migrate the virtual domains one by one - and I will
> also have to face the fact that the update of the MX record for the
> domain will take some time. Thus, for some time, mail will arrive an
> both the old and new locations from various sources.
>
> Therefore I'm thinking about a solution where I can tell the old mail
> server to accept the mail for the specific virtual host, but to
> forward it immediately to the new server.

Yes, that's the right approach. When the new server has been set up,
convert the domain to a relay domain and list the valid recipients in
relay_recipient_maps. If you've made the MX record switch and that
change has propagated to the old server you're done. Otherwise, use the
transport table to force the mail routing to the new server.

http://www.postfix.org/postconf.5.html#relay_domains
http://www.postfix.org/postconf.5.html#relay_recipient_maps
http://www.postfix.org/postconf.5.html#transport_maps
http://www.postfix.org/transport.5.html

> Thus, even if the mail goes to the old server, it will land at it's
> new and correct location. Of course, this should only be working for
> the duration of the transition period.
>
> I was looking at the documentation here:
> http://www.postfix.org/VIRTUAL_README.html where there is a catch-all
> virtual domain forwarding configuration - but that would forward all
> mail to a single mail account. What I'm looking for is to forward a
> complete domain - that is, all mail destined for that domain to be
> forwarded to a different server, with the same recipient e-mail
> address.

Virtual aliasing is only the right tool if you wish to change the
envelope recipient addresses, but in this case you want to change
the routing and leave the message envelope and contents intact.

--
Magnus Bäck
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Luciano Mannucci
In reply to this post by Maróy Ákos
On Thu, 30 Jul 2009 10:35:21 +0200
Maróy Ákos <[hidden email]> wrote:

> I'm planning to migrate the virtual domains one by one - and I will also
> have to face the fact that the update of the MX record for the domain
> will take some time. Thus, for some time, mail will arrive an both the
> old and new locations from various sources.
Use transport.
You can do it for each domain, or even for each user if you care about
beeing able to reject mail for non-existent users at the SMTP port.
I did both and I found it straightforward... :-)

Cheers,

luciano.
--
 /"\                         /Via A. Salaino, 7 - 20144 Milano (Italy)
 \ /  ASCII RIBBON CAMPAIGN / PHONE : +39 2 485781 FAX: +39 2 48578250
  X   AGAINST HTML MAIL    /  E-MAIL: [hidden email]
 / \  AND POSTINGS        /   WWW: http://www.mannucci.ORG/
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
Luciano,

> Use transport.
> You can do it for each domain, or even for each user if you care about
> beeing able to reject mail for non-existent users at the SMTP port.
> I did both and I found it straightforward... :-)

thanks for the info. so, I create a /etc/postfix/transport file, with
say the following line:

example.com    smtp:newmachine.example.com:25


and remove example.com from the virtual domain table I guess.


and then what else do I have to set?


Akos

Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Barney Desmond
2009/7/30 Maróy Ákos <[hidden email]>:
> thanks for the info. so, I create a /etc/postfix/transport file, with say
> the following line:
>
> example.com    smtp:newmachine.example.com:25

The right-hand side of the transport file should have square brackets
around the hostname. By default, Postfix would attempt to lookup the
MX for newmachine.example.com, which isn't what you want. Square
brackets suppress the MX lookup, and use the direct host lookup
instead. ie.:

example.com     smtp:[newmachine.example.com]:25

> and remove example.com from the virtual domain table I guess.

I'm pretty sure you leave it in, Postfix has to know it's meant to
handle the domain, which means either being "local", "relay" or
"virtual" (two types).
http://www.postfix.org/ADDRESS_CLASS_README.html

> and then what else do I have to set?

I might have forgotten something, but I think that's it. Just remember
to `postmap` the /etc/postfix/transport file and add it to your
transport maps.
http://www.postfix.org/postconf.5.html#transport_maps
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Luciano Mannucci
In reply to this post by Maróy Ákos
On Thu, 30 Jul 2009 13:25:18 +0200
Maróy Ákos <[hidden email]> wrote:


>
> thanks for the info. so, I create a /etc/postfix/transport file, with
> say the following line:
>
> example.com    smtp:newmachine.example.com:25
You do not need the :25 if the transport is smtp (though it shouldn't harm)

> and remove example.com from the virtual domain table I guess.
If you remove it from virtual domain table you'll have to add it to
mydestination (mydestination = whatever_it_as, example.com)

> and then what else do I have to set?
Check that transport_maps looks moreless like:
"transport_maps = hash:/etc/postfix/transport"
using "postconf transport_maps" command.

Cheers,

luciano.
--
 /"\                         /Via A. Salaino, 7 - 20144 Milano (Italy)
 \ /  ASCII RIBBON CAMPAIGN / PHONE : +39 2 485781 FAX: +39 2 48578250
  X   AGAINST HTML MAIL    /  E-MAIL: [hidden email]
 / \  AND POSTINGS        /   WWW: http://www.mannucci.ORG/
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
In reply to this post by Barney Desmond
Dear Barney,

> The right-hand side of the transport file should have square brackets
> around the hostname. By default, Postfix would attempt to lookup the
> MX for newmachine.example.com, which isn't what you want. Square
> brackets suppress the MX lookup, and use the direct host lookup
> instead. ie.:
>
> example.com     smtp:[newmachine.example.com]:25

thanks, so I've set this in /etc/postfix/transport, then ran postmap on
the file, then aded:

transport_maps = hash:/etc/postfix/transport

to /etc/postfix/main.cf

>> and remove example.com from the virtual domain table I guess.
>
> I'm pretty sure you leave it in, Postfix has to know it's meant to
> handle the domain, which means either being "local", "relay" or
> "virtual" (two types).
> http://www.postfix.org/ADDRESS_CLASS_README.html

ok, so I have my example.com in my vdomains file, and I have this in the
defined as:

virtual_mailbox_domains = /etc/postfix/vdomains

>> and then what else do I have to set?
>
> I might have forgotten something, but I think that's it. Just remember
> to `postmap` the /etc/postfix/transport file and add it to your
> transport maps.
> http://www.postfix.org/postconf.5.html#transport_maps

thanks. but now I'm getting:

550 5.1.1 <[hidden email]>: Recipient address rejected: User unknown in
virtual mailbox table


where of course the user is not in the mailbox table, as the idea would
be that all mail is just transported to the other mail server..

what am I doing wrong?


Akos
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Barney Desmond
2009/7/31 Maróy Ákos <[hidden email]>:

>> I'm pretty sure you leave it in, Postfix has to know it's meant to
>> handle the domain, which means either being "local", "relay" or
>> "virtual" (two types).
>> http://www.postfix.org/ADDRESS_CLASS_README.html
>
> ok, so I have my example.com in my vdomains file, and I have this in the
> defined as:
>
> virtual_mailbox_domains = /etc/postfix/vdomains
>
> <snip>
> thanks. but now I'm getting:
>
> 550 5.1.1 <[hidden email]>: Recipient address rejected: User unknown in
> virtual mailbox table
>
> where of course the user is not in the mailbox table, as the idea would be
> that all mail is just transported to the other mail server..

Okay, I was a little ambiguous there. You want virtual_alias_domains
instead of virtual_mailbox.
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
In reply to this post by Luciano Mannucci
Luciano,

> If you remove it from virtual domain table you'll have to add it to
> mydestination (mydestination = whatever_it_as, example.com)

oh, it worked this way.

thank you all for the help!


Akos

Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Brian Evans - Postfix List
In reply to this post by Maróy Ákos
Maróy Ákos wrote:

>>
>> I might have forgotten something, but I think that's it. Just remember
>> to `postmap` the /etc/postfix/transport file and add it to your
>> transport maps.
>> http://www.postfix.org/postconf.5.html#transport_maps
> and then what else do I have to set?
>
> thanks. but now I'm getting:
>
> 550 5.1.1 <[hidden email]>: Recipient address rejected: User unknown
> in virtual mailbox table
>
>
> where of course the user is not in the mailbox table, as the idea
> would be that all mail is just transported to the other mail server..
>
> what am I doing wrong?
>
>
> Akos
IMO, you should follow Magnus' post and use relay_domains and
relay_recipient_maps if you are moving complete virtual mailbox domains
at one time.
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Brian Evans - Postfix List
In reply to this post by Maróy Ákos
Maróy Ákos wrote:

> Luciano,
>
>> If you remove it from virtual domain table you'll have to add it to
>> mydestination (mydestination = whatever_it_as, example.com)
>
> oh, it worked this way.
>
> thank you all for the help!
>
>
> Akos
>
This is very wrong.. see my previous posts.

Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
In reply to this post by Brian Evans - Postfix List
Brian,

> IMO, you should follow Magnus' post and use relay_domains and
> relay_recipient_maps if you are moving complete virtual mailbox domains
> at one time.

I see. but can you be more specific, maybe with an example on what and
how to set?


Akos

Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
In reply to this post by Brian Evans - Postfix List
Brian,

> This is very wrong.. see my previous posts.

now I've set:

relay_domains = $mydestination, example.com
relay_transport = smtp:[newserver.foo.bar]
relayhost = [newserver.foo.bar]


and it forwards mail destined for example.com fine - but not my mail
server does not work as an outgoing mail server - so if I send e-mail as
an authenticated smtp client, I get a relay denied message.

so how can I make it work both ways?


Akos
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Brian Evans - Postfix List
Maróy Ákos wrote:

> Brian,
>
>> This is very wrong.. see my previous posts.
>
> now I've set:
>
> relay_domains = $mydestination, example.com
> relay_transport = smtp:[newserver.foo.bar]
> relayhost = [newserver.foo.bar]
>
>
> and it forwards mail destined for example.com fine - but not my mail
> server does not work as an outgoing mail server - so if I send e-mail
> as an authenticated smtp client, I get a relay denied message.
>
> so how can I make it work both ways?
Do not set relayhost on the edge machine.
relayhost means where to default route every mail.

You should not need $mydestination in relay_domains unless you want
those in mydestination to go to newserver.foo.bar
Also, setup relay_recipient_maps to stop BackScatter.

You did not show 'postconf -n', so I cannot say what should go where
when talking about your local domains (aka mydestination).

The reason for all of this is to separate the Address Classes.
http://www.postfix.org/ADDRESS_CLASS_README.html
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Magnus Bäck
In reply to this post by Maróy Ákos
On Thursday, July 30, 2009 at 17:32 CEST,
     Maróy Ã?kos <[hidden email]> wrote:

> > IMO, you should follow Magnus' post and use relay_domains and
> > relay_recipient_maps if you are moving complete virtual mailbox
> > domains at one time.
>
> I see. but can you be more specific, maybe with an example on what and
> how to set?

/etc/postfix/main.cf:
relay_domains = example.com
relay_recipient_maps = hash:/etc/postfix/relay_recipients

/etc/postfix/relay_recipients:
[hidden email]       whatever
[hidden email]       whatever
...
[hidden email]       whatever

example.com obviously being the domain you're moving. Do not list
the domain in virtual_mailbox_domains, virtual_alias_domains, or
mydestination.

--
Magnus Bäck
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: forwarding mail for a complete virtual domain to another mailserver?

Maróy Ákos
In reply to this post by Brian Evans - Postfix List
Brian,

> Do not set relayhost on the edge machine.

unsetting relayhost makes everything work.

thank you!


Akos