How do I set up email for the primary domain from a subdomain?

How do I set up email for the primary domain from a subdomain. eg I want email for example.com when I have a virtualmin server emailbox.example.com?

The background is we are already serving web pages for our primary domain using a dedicated server (not on virtualmin) say this is example.com. We want to set up a second server for email and mailman and round cube to do our email handling. We can call this eg emailbox.example.com, but it should service the email for example.com and not emailbox.example.com. We use name cheap for the DNS.

(I can somewhat easily set up everything I need to emailbox.example.com) but in the end I would like to use something like:

What would the best way to do this be?

Thanks in advance!

It sounds like you have emailbox.example.com already running on Virtualmin. Just create a new virtual server as normal for example.com, and then point example.com’s MX records to it. Don’t change it’s A and AAAA records - web traffic will continue to go to the other server. You can optionally uncheck “Setup website for domain? / Setup SSL website too?” when you create the new server, but don’t need to. Web traffic will just never end up there.

You can access any email accounts managed by the underlying server because you log into Roundcube using your email addresses. Often, webmail occupies another subdomain, or masquerades as one through web server redirect. This works best if you have wildcard DNS enabled. To be on the safe side, you should consider configuring Roundcube to appear at something like emailbox.example.com/webmail/. It works fine within an Iframe so you can embed it in any other website you like.

It sounds like you have emailbox.example.com already running on Virtualmin.

Yes.

Just create a new virtual server as normal for example.com, and then point example.com’s MX records to it. Don’t change it’s A and AAAA records - web traffic will continue to go to the other server. You can optionally uncheck “Setup website for domain? / Setup SSL website too?” when you create the new server, but don’t need to. Web traffic will just never end up there.

Cool. I have that setup and it works well. So to make this concrete lets say our main web server is on digital ocean 10.20.30.40. this new virtualmin email server is at vultr 50.60.70.80

So name cheap DNS for example.com is configured like:

So in virtualmin I have created a virtual server: example.com

You can access any email accounts managed by the underlying server because you log into Roundcube using your email addresses. Often, webmail occupies another subdomain, or masquerades as one through web server redirect. This works best if you have wildcard DNS enabled.

Sorry I am not sure what you mean here. The SSL certificates I set up on our test box are currently done by let’s encrypt but our general ssl certs are *.example.com if that’s what you are asking?

To be on the safe side, you should consider configuring Roundcube to appear at something like emailbox.example.com/webmail/.

That would be great! How do I do that? When I install roundcube . I selected Virtualmin > Install Scripts > roundcube : Install sub-directory under ‘webmail’. The response is now: Now installing RoundCube version 1.1.4-complete …
RoundCube installation complete. It can be accessed at http://example.com/webmail/

How do I get this moved / redirected to http://emailbox.example.com/webmail/ ?

Thanks! Jason

Well, the web instance of example.com on your Virtualmin server is just a placeholder. It’ll never receive web traffic, only email. You can uninstall roundcube from example.com. Then, select emailbox.example.com and then run the roundcube installer again. The web gui will use that subdomain’s certificate. I suppose the email server will use example.com’s cert, but this is a different application from the web gui so there is no conflict.

Ahh… Sorry. When you asked if I had virtualmin running on emailbox.example.com I possibly answered wrong. That is our virtualmin server. I only have / had one virtualmin virtual server: example.com. But I guess I could have two virtualmin servers: example.com and webmail.example.com (another top level server. Then just install round cube on webmail.example.com, then the users use the login from example.com. That would work! What about usermin though? How would users access the usermin for example.com?

A related point: I just tried creating this second virtual server webmail.example.com and I got: Failed to create virtual server : The domain webmail.example.com is already hosted by your Apache web server (But creating something different like roundcubel.example.com worked. (Is that due to having a DNS record for this at namecheap?)

Jason, I thought you were pretty clear in your first post that example.com is your primary web server hosted somewhere else, and that your Virtualmin server is already managing emailbox.example.com, and you want it to manage example.com’s mail and host the roundcube web gui as well. Now you’ve just made a very big revision to that layout. The location of the components matters a lot in order to have a valid context and provide the right instructions.

Roundcube can optionally install a server redirect which creates a pseudo-subdomain. This is what the script installer means by “Install sub-directory under www -vs- At top level” You won’t see such pseudo-subdomains appear in Virtualmin’s list to select from, but as you’ve discovered, you won’t be allowed to create a real subdomain which conflicts with it. It behaves like a “top level server” but in reality is just a redirect within another server’s Apache server container.

Since Virtualmin is telling you that webmail.example.com is reserved, we will assume you created a placeholder duplicate of example.com on your Virtualmin server, and that installing roundcube on the placeholder version of example.com succeeded. Now, configure your DNS registration to define webmail.example.com as a subdomain, and supply the IP address of your Virtualmin server. Example.com and webmail.example.com can be at different IPs, which is what I take your original situation to be.

Let me know how it goes!

Sorry! Yep. I am doing this all on test domains right now (I have registered some example.xyz and example.site, and example.online domains to play around with so I get this straight before deploying it.) So I can actually access example.xyz. In the future once I have the layout working, I will move this into production and do this on our example.com dns.

Jason, I thought you were pretty clear in your first post that example.com is your primary web server hosted somewhere else

Exactly!

and that your Virtualmin server is already managing emailbox.example.com
Opps. emailbox.eample.com is our server webmin / virtualmin server. I have set up a virtualmin virtual server example.com and email is working on that domain.

and you want it to manage example.com’s mail and host the roundcube web gui as well.

Exactly!

Ok. So we have:

I think I have got this. I am out of time today but will try to get this to go within the next 12 hours… Thanks for your help!

One last question the usermin on virtual server example.com how does the user access this?

Thanks!

Hmmm, I see some persistent signs that you and I are using certain terms differently.

However, I think what you need to do at this point is select “webmail.example.com” in Virtualmin (which is a real domain you created, and was not created by the roundcube installer) and install roundcube “in subdirectory under www”. Then your roundcube webmail will be accessible at webmail.example.com/roundcube. Usermin will be accessible at webmail.example.com:20000

You could still have roundcube show up at “webmail.example.com” as a pseudo-subdomain, but you’ll have to delete the real subdomain “webmail.example.com”, and then install roundcube “at top level” on the placeholder copy of example.com. But I don’t think you would be able to access Usermin at webmail.example.com:2000 because it would mean two conflicting redirections.

Ok. So I got this working and most things seem to be working. What I have:

Results:

Remaining problems: I can’t seem to view mailman archives for example.com. It seems to be going to eg (for a list named devops) https://example.com/pipermail/devops/

I looked in /etc/mailman/mm_cfg.py and couldn’t see a setting to change the webhost to emailbox.example.com? (The urls already had emailbox.example.com) Would you know where the correct setting for mailman is? I looked around on google but didn’t immediately see anything. (there was some talk of using something like:

./withlist -l -r fix_url list_name --urlhost=host2.domain.com

But that is list by list and not all the lists freshly created in the future, etc…

I installed round cube at the "top level
Results: - From https://webmail.example.com it comes up with roundcube

Glad that worked. It seemed to me to be courting trouble.

The users for email turned out to be: jimmyh.example and janed.example

That’s configurable. You can’t change it for an established virtual server, so you’ll have to delete it and change an option when you create a new server: Virtualmin | Create Virtual Server | Advanced Options | Prefix for mail usernames.
As the help bubble for that feature says, also see: “Module Config” wherever the hell it is. I’ve seen it before. I just wasted 25 minutes digging around for it. I give up. I wonder sometimes if Virtualmin wouldn’t be more popular if it were organized and de-duped. It’s really frustrating.

FWIW, none of my users have to use username.hostname suffixes. I think it only adds the suffix if you’re trying to add a username which already exists on the server. That includes any of the virtual servers.

I wish I could help you with the mailing list, but I have no experience with it. I’d start a new topic for it.

Brilliant! Thanks for the bit about the username prefix. I just found it now. When I set this up in production I will change this to have no prefix. Thanks!

Thanks for the great help! I will start a new ticket thread!

Thanks! Jason