How to setup imap/smtp mail for use in mailclient for subserver using webmin postifx and dovecot

Hello,

I have been trying whole day to setup e-mail using webmin`s modules dovecot and postfix on my VPS.

I have a main domain (let call it mydomain.com), and a sub-server domain , lets call this one mysubserver.com

On mydomain.com I added Mx record mail.mydomain.com. If I add a user to mydomain.com using virtualmin, I can succesfully connect to this account using smtp and I can receive emails in my mail client, or inbox on webmin (sending mails do not work yet). However, as mentioned I have setup a sub-server (and more to come in the future). I created a account: mailadres@mysubserver.com.

Basically, what I want to do is this:

How to set this up?

PS. mailing on my sub-server does not work at all. I enabled e-mail for this domain, and dovecot, postfix, etc is running. However, I cannot connect to this domain via SMTP or IMAP using either mail.mysubserver.com or mail.mydomain.com.

What to do? Any step by step guide on how to set this up?

Thanks!

Before trying to fully understand your problem, an initial question: You’re talking about creating a user in Virtualmin, but then about using the Webmin modules for Postfix and Dovecot to configure stuff and manually creating MX records.

If you’re using Virtualmin (which is highly recommended), you don’t need to fiddle with the low-level modules in Webmin at all (neither Postfix, nor Dovecot, nor creating the MX records), at least not for the basic stuff like creating email accounts.

Can you clarify your system layout and operation in that regard please?

Hi, thanks for your reply. I have been trying everything!

The thing is, I host by DigitalOcean. They require DNS setup in their controlpanel instead of in VirtualMin. So i have setup these records in their DNS management for mail

I was thinking I needed to edit the postfix server or something, because it was not working. And I have read that postfix is required for using e-mail in mailclient like Outlouk.

However, I can now succesfull receive mails from usermin. However, I cannot sent mails. The following error appears in the mail.
log:42C06629C7: to=existingmailadres@domain.com, relay=none, delay=312, delays=311/0.01/0.94/0,
dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for
name=domain.com type=MX: Host not found, try again)

What can I do to fix this? And how to configure my mail as IMAP in Outlouk afterwards? Thanks!

The error sounds like a problem with name resolution on your server. You can test it with dig in a shell, or use the “Re-check configuration” in Virtualmin to see if DNS is set up properly. If you have Virtualmin installed, you generally want to use “127.0.0.1” (i.e. the local BIND) as name server. Otherwise use that of your hoster/ISP.

Can you elaborate “how to configure mail in Outlook”? What question do you have about it specifically? My general answer would be “follow Outlook’s wizard for creating new accounts”.

Thank you for the quick reply!

Id did configuration check in virtualmin and get the following messages which may be of interest:

  • Postfix can support per-domain outgoing IP addresses, but is not currently configured to do so. This can be setup in the Postfix Mailserver module.
  • Virtualmin could not work out the default IPv6 address for virtual servers on your system. You will need to update either the Network interface for virtual addresses or Default virtual server IP address fields on the module configuration page. <= this one is bold
    -Quotas are not enabled on the filesystem / which contains home directories under /home and email files under /home. Quota editing has been disabled.

The second message seems like an possible issue to me for emailing. However, when I go to virtual server configuration I do not see what I need to change. I can choose a configuration category, which opens in server setttings. All I can do there is check mail server to configure and do some settings. When I switch to category network settings, I can enter info about IP adresses, but I have no clue what to do?

I did a dig comment, it returns this:

:~# dig redhat.com

; <<>> DiG 9.8.1-P1 <<>> redhat.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58449
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;redhat.com. IN A

;; ANSWER SECTION:
redhat.com. 2 IN A 209.132.183.181

;; Query time: 21 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Jan 21 16:39:42 2014
;; MSG SIZE rcvd: 44

Seems fine right?

Addition:

If I restart postifx, I get this message:
warning etc/resolv.conf and /var/spool/postfix/etc/resolv.conf differ

I opend both files, the first contains 3 nameserver records, ip`s: 127.0.0.1, 4.4.4.4, 8.8.8.8. The latter contains completely different NS records, more like the DNS records of Digitalocean I think.

What does it need to be, could the problem be here?

Hi! I am now able to mail from usermin. It had to do with the 2 differtent files. The records for both files are now:

  • 127.0.0.1
  • 4.4.4.4
  • 8.8.8.8
    Thanks so far!
    However, I cannot sent mails through my mail client. What port do I need to use?

And additional question: I have now postifx and dovecot running. Is this nessecary? I want to reduce load as much as possible.

YEAH! It is working in Outlouk, I was using wrong port.
Then the final question, which I actually started with:

I now have mail up&running for 2 domains on my VPS, however, I would like to have one central mailserver (my main virtaulmin server). I will create up to 10 light sites (sub-servers), but I don`t want to go through the email configuration part for every sub-server. Is that possible? To automatically let users for sub-servers be using the mailserver of the main server? It is kind of a shared hosting idea, where it is often possible to do so.

Read my first post in this thread for a better explaination. Thanks a lot!

Thanks!

Okay, good that it works! :slight_smile:

The Virtualmin re-check messages you got are not relevant for Postfix. The quota one might be a problem if you need quotas; we’ll have to debug this separately though.

Generally, you want the resolv.conf files in those two locations to be identical. Copy the one from /etc to the other location if in doubt.

The nameservers you’re using now are Google’s ones. Those should be okay, but you might want to use those provided by your hoster instead. They’re probably more reliable. But if it works, it works.

To send mail from your client to Postfix, you’ll normally want port 465 and turn on SSL, so the communication is encrypted. If that’s not possible or required, use port 587 (submission, special port for local clients) if available, otherwise 25.

Postfix is for sending out and receiving mail (SMTP), Dovecot is for fetching and reading it (POP3, IMAP). So you’ll need both if you want to do that.

Hi Thanks for the quick and clear explanation. I am a newby to this, but I have learned so much already!

I will swich to SSL soon, but have not yet installed any certificate.

“Postfix is for sending out and receiving mail (SMTP), Dovecot is for fetching and reading it (POP3, IMAP). So you’ll need both if you want to do that.”
-> I am now checking my server configuration and what I notice is that Dovecot is currently NOT running. However, I am connecting through imap via mail.mysubserver.com, and this works. I can sent and receive mails. I think dovecot is actually running because when I check log I see message dovecot: … But virtualmin says it is currently not running, strange…

However, I want to use IMAP to keep sync with colleagues and to keep everthing also on server. Then I need dovecot right?

And what about my lates question, to use just one mail mailserver, instead of having to set this up for every single domain?

Thank you so much!

Seems you added your question about the “central mailserver” after I started typing my last reply. :slight_smile:

I don’t fully get that question though. You generally only have one mailserver (i.e. one instance of Postfix+Dovecot+etc.) installed and running on your server, just like you have only one webserver (Apache) that serves all your pages. Well actually Postfix, just like Apache, automatically spawns child processes for your several domains and stuff, but you don’t need to worry about that.

What exactly is it that you don’t want to repeat for each domain / want to automate for your sub-servers?

If Virtualmin says Dovecot is not running, but you can use IMAP, it’s possible that VM is looking in the wrong place for Dovecot’s process ID file. Check the Webmin module config for Dovecot, or click the “Start Dovecot” button to see if that fixes it.

To verify low-level if Dovecot really is running, you can do netstat -tpln | grep :143 in a shell, that should show an output line if Dovecot is listening on port 143 (IMAP).

If you want to use IMAP, you need Dovecot, yes. (Or an alternative POP3/IMAP daemon, but I’d stick with Dovecot since it works well and Virtualmin knows how to configure it.)

Thanks!

I will stick with dovecot, everything is working fine now!

“What exactly is it that you don’t want to repeat for each domain / want to automate for your sub-servers?”
Well, I now for every subserver have to add this DNS record: mail.mysubserver.com, including a MX record for it. Then I have to create mail accounts for that subserver, and I can connect using my mailclient through mail.mysubserver.com.

However, on my sharedhosting company I was previous, I hosted a few sites. But using mail settings, I could connect throug mail.myhostsservername.com, instead of mail.mywebsitename.com.

Why this is ideal is beacause if I want to mail via SSL, I don`t need an SSL certificate for every server, but just for my mainserver. Also, configuring e-mail would not require changing DNS records for every sub-server.

I hope the following example makes it clear:

In my current setup, using the mail for user1 and user2 would require to setup NS records for mail.subserver1.com. However, I want wan central site for my mailing. IN this case, I want to user mail.mainserver.com, for the mailadres user1@subserver1.com

SSL is generally just for one domain, or if I use a multi-domain certificate it costs a lot. So it would be iDEAL to have SSL certificate on my mainserver, and use that for mailing. Also, I am running virtualmin on my mainserver.com:10000, now I don`t have a certificate, but I want to use the same certificate there too.

Thanks again for your help, I hope you understand my question better now!

Well if your users of your sub-servers are supposed to get email addresses like “userN@subserverN.com”, you won’t get around creating MX records for “subserverN.com”. This is something that Virtualmin normally does automatically for you - i.e. create the proper BIND zone for new virtual servers - if you use nameserver delegation instead of creating the MX and A records at your hoster.

Normally you’d tell your hoster to forward queries for “domain.tld” to your server, by creating the proper NS record there. Then the BIND on your server will do the further resolution for “domain.tld” and everything under “*.domain.tld”.

If your sub-servers have independent domain names though, i.e. are not subdomains of your main one, you will still need to have them all point to your server individually at your hoster, there’s no way around that. Normally this requires just one additional configuration step when ordering the domain though, namely tell it the nameservers to use in addition to what person to register the domain for.

The thing with the SSL certificate is independent from that though. The need to have MX records for all of your domains is only for receiving email. Your users can, even if their address is like “userN@subdomainN.com”, still use the hostname “maindomain.com” when they connect to your server. As long as that hostname resolves to the correct IP address, it does not matter which hostname you use.

Thank you for the clear explaination. It is all making more and more sense!

However, I am trying to setup use so that users indeed can use userN@maindomein.com. At the moment this failes. How do I need to setup DNS fot his to work.

I now have a Mx record mail.maindomein.com. and an A record mail.maindomain.com which points to the VPS`s IP adress. Using mail for users I have added to my maindomain works. However, users added to my subdomain cannot imap via hostname mail.maindomain.com.

DIgitalOcean doesn`t allow nameservers to be configured within virtualmin, but have their own DNS manager. But it should work the same, so why is it not working?

Or do I need to add a Mx record to maindomain.com for mail.subserverN.com?

I think I am almost there, just a tiny part I not understand 100%. I mean, mail.maindomain.com resolves to the same IP as mail.subserverN.com. But it is not working for email@subserverN.com to use maindomain.com as hostname for e-mailing.

MX records have nothing to do with your users logging into your server, they are only for mail being sent to your server from the outside. I.e. the source mail server queries the DNS for the MX record for the destination domain and connects to that host on port 25.

Virtualmin will create users in its respective virtual servers with the respective domain name as part of the username, depending on your settings (you can configure this behavior). So your users could use “maindomain.com” as hostname, but still have to use “userN@subdomainN.com” as username, or a variant of that depending on your settings. Which means, the hostname used for connection is independent from a potential hostname/domain part in a username.

Ok, that makes sense.

But why isn`t my current setup working? I mean, I am trying an imap connection to mail.mydomain.com. As long as I use an user which ends with @mydomain.com, this works fine. But when I try a user ending with @mysubserverdomainname.com , it does not work.

This is stupid!

It is working now :slight_smile: I have been messing around with ports, and that was why it was not working.

Thanks a lot, and forget about my last question.

Everything is now up and running!