Two options actually:
- When you have control over the
example2.com
mail server(s):
in most mail server software you can add an alias domain such that for any existing mailbox@example2.com
mailbox the corresponding email address mailbox@example.1.com
will also get accepted and delivered there.
You will need to look up existing MX DNS records for example.2.com
for instance with dig MX example.2.com
and set the same one(s) for the example.1.com
domain. That would result in something like
example1.com. IN MX 5 smtp.example2.com.
example1.com. IN MX 10 relay.example2.com.
And then configure those existing mail server ([smtp | relay].example2.com.
) to accept mail for the new alias domain.
- When you don't have control over the
example2.com
mail server(s):
You will need to run on your VPS your own SMTP server (for instance postfix, exim, sendmail) that will accept mail for @example1.com and for each email address forward the message to the corresponding email address @example2.com.
You will need to create DNS MX records to deliver incoming email for @example1.com to your VPS:
example1.com. IN MX 5 smtp.example1.com.
smtp.example1.com. IN A <ip-address of your VPS>
And then set up for instance with postfix: How to redirect all mail from one domain to another in Postfix?