Website on Virtualmin and Email hosted on Office 365

Operating system: Ubuntu
OS version: 20.04

So I have used Virtualmin for years hosting several of my websites.
Lately we need a better email and calendar solution than what IMAP can provide, so have chosen to use MS Office 365 for my main company website email service provider (

I have the DNS MX records and mail setup and its working well with for

Another part of my company has another domain name ( with basic website.
I want a to forward to my main Office 365 email address

When I send an email to the which I forward to the server sees it and in the mail.log I see:
Nov 27 09:30:00 hostname postfix/local[152530]: A0FA980478:,, relay=local, delay=0.03, delays=0.01/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: “”)

For the first website ( I have the Mail feature disabled (in edit virtual server).
The second website ( Mail is enabled and I use this to forward from this to my first email address (

I do not have any users setup on as there is no email hosted on this server, hence the message from the mail.log as above.
I can see whats happening I think, where the domain part is matching the virtualhost and is trying to be delivered locally on the server, but it needs to be sent out to the internet where it will see the mx record (on cloudflare.dom) and be delivered to my Office 365 account.

I hope you can follow this and there is a solution to push the email out from my server to the internet for the NS/DNS lookup.

Many thanks and regards.

In your Virtualmin DNS, edit the records for mainwebsite to reflect the actual DNS records, particularly the MX records for the domain. There is currently a disparity between the Virtualmin DNS records and the actual DNS records for mainwebsite due to which Virtualmin / Postfix is attempting to deliver email for to localhost instead of Office 365 servers, as you have correctly surmised, @wozie

Virtualmin → Server Configuration → DNS Records

Thanks for your fast reply.

I have added a MX record now: 1h IN MX 0

When I send to this email: it still shows a bounce in the log with the same error:
Nov 27 11:26:19 hostname postfix/local[152530]: 790CA8094F:,, relay=local, delay=0.03, delays=0.01/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: “”)

Seems still to look on this server for the user on this domain and not looking out. Did I set the TTL too high?

Restart BIND if you don’t want to wait for the records to propagate.

Apologies, I did restart Bind9: “systemctl restart bind9” forgot to add it to the last post.

FYI: I copied the DNS settings for the MX record from my working existing settings on cloudflare to the server as above. However the Priority on Cloudflare is 1 and on my server is Priority 0.

I can confirm I am still seeing the bounce in the mail.log.

That’s strange, it should work the way you want it to after you apply the MX records to Virtualmin’s DNS and restart BIND… :thinking:

Perhaps someone else can suggest an alternate solution?

Yeah, your solution made sense to me to tell it to look elsewhere for the user with the addition of the MX record. Strange it is still looking on the server for the “” user.

Just looking in /etc/postfix/
$myhostname =
mydestination = $myhostname,,, , localhost

But I have disabled the mail function for the server in the Virtualmin gui - Edit Virtual Server.

Ah, I had assumed (and it is Virtualmin’s recommendation) that hostname be a subdomain such as and if it is not then, of course, merely adding a MX will not do the trick in your case.


So I added the subdomain: in the file.

This sent the email to the Microsoft office 365 server ok now but the O365 server is bouncing the emails back with the following:

Nov 27 12:26:58 hostname postfix/smtp[255935]: 842C28049A:,,[]:25, delay=0.21, delays=0.01/0.02/0.08/0.1, dsn=5.4.1, status=bounced (host[] said: 550 5.4.1 Recipient address rejected: Access denied. AS(201806281) [] (in reply to RCPT TO command)

So from this, I can see it is now malforming the to email address to - this is not being recognized by the Office 365 server and bouncing it (the email should be:

It is also sending emails sent from my system: to O365 and these are also bouncing.

I have changed back and removed the subdomain “server” from the file for the meantime.

Thanks for your help


Now all you need to do is configure Virtualmin the way the official documentation specifies and all will be well.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.