I want to send mail to an outside Office 365 account with the same domain I have for local accounts.
When I try to send mail to this address outside, Postfix rejects it with error "Account not available".
So, I want Postfix to send mail to outside account for same domain, if that account is not present locally.
For example I have two email address abc@example.com
and xyz@example.com
.
abc@example.com
is present in local serverxyz@example.com
is an account on Office 365 external mailserver.
Now, I want to send mail to xyz@example.com
from Postfix from any local account. The domain example.com
is added to relay_domains
also, but Postfix still rejects mail with error "recipient not present".
Best Answer
As you already have
example.com
as a local domain configured in eithermydestination
orvirtual_alias_domains
you can't achieve this by also adding it torelay_domains
.Instead, you should add a transport(5) map that can override delivery rules defined by the default
transport:nexthop
used bymydestination
,virtual_alias_domains
etc.Add transport_maps to your
/etc/postfix/main.cf
:And then add to
/etc/postfix/transport
:(Remember to
postmap /etc/postfix/transport
as you are usinghash
, Berkeley DB lookup table.)This will use default transport rules for all
@example.com
and anything else (*
) leaving other delivery configuration as is, but forward all email toxyz@example.com
to Office 365 via SMTP: the default pattern for Office 365 MX record for companies is<domain>.mail.protection.outlook.com.
Using
transport_maps
is a global solution that will work with any external SMTP server. In a specific scenario, where a) the external account is on Office 365 and b) domain is configured on Postfixvirtual_alias_domains
it could also be possible to add a virtual alias redirecting all mail to Office 365 user's initial domain (tenant) address,xyz@example.com xyz@contoso.onmicrosoft.com
.