Let's Encrypt provides free SSL certificates, which can be used for hMailserver. However, the certificates are valid only for 90 days, and there is a scripted validation process that can be challenging to set up. Most scripts that are available are designed for validation using a webserver, and not mailservers. The following enables SSL full certificate request and installation for hMailserver without a separate webserver, with renewals every 85 days.
Requirements:
- hMailserver needs to be installed on Windows 10, with a working WSL (Windows Subsystem for Linux). If you need help to enable WSL, see the instructions for setting up Windows 10 Bash . In this page, we will be calling Windows 10 Bash, as Bash.
- You will need to migrate your DNS Nameserver to CloudFlare. You can use an alternate service provider if it is supported as a dehydrated hook, but will need to modify the scripts provided on this page to make the other DNS provider work.
- The scripts here assume that hMailserver is installed in c:Program Files (x86)hMailServer if you have it installed in a different location, you will need to modify the batch file to use the correct path.
However, you can decrypt that certificate to a more readable form with the openssl tool. $ openssl x509 -text -noout -in certificate.crt. It will display the SSL certificate output like expiration date, common name, issuer, Here's what it looks like for my own certificate. $ openssl x509 -text -noout -in certificate.crt Certificate. I have created a self-signed SSL certificate using OpenSSL, and I added it to hMailServer accessible in the private network. I used this certificate on port 465 and 993 to run SMTP and IMAP. Ssl openssl ssl-certificate thunderbird hmail-server. Now that an SSL certificate has been installed in hMailServer, go back to your email client and reconfigure your email account to use the following settings, as shown in the screenshot below. Take note of the Port and SSL values having changes to the new TCP/IP port configuration that you created in the previous section. Openssl verify chained.crt does not (directly) verify a chain as you seem to think; it reads one (the first) cert from the file and verifies it against the truststore. Here the first cert is your server (leaf) cert which is issued by your first intermediate (Comodo DV-server) which is not in the truststore so lookup fails.
Prerequisites:
sudo apt-get install openssl curl sed grep mktemp git build-essential
sudo apt-get install python-dev curl libffi-dev libssl-dev python-pip
sudo easy_install pip
c:UsersmyUserNameDocumentsNetworkinghmailserver_letsencrypt
(change myUserName to your username). We will call this your script folder on this page.One-time initial setup
git clone https://github.com/lukas2511/dehydrated
cd dehydrated
mkdir hooks
git clone https://github.com/kappataumu/letsencrypt-cloudflare-hook hooks/cloudflare
sudo pip install -r hooks/cloudflare/requirements-python-2.txt
cd ..
Verisign Ssl Certificate
hmailCert.sh
by following:cat > ./hmailCert.sh
#!/bin/bash
export CF_EMAIL='yourCloudflareEmail@somedomain.com'
export CF_KEY='yourCloudflareAPIKey'
export HMAILSERVER_DOMAIN='yourMXDomainNameLike_mail.mydomain.com'
dehydrated -c -d $HMAILSERVER_DOMAIN -t dns-01 -k 'hooks/cloudflare/hook.py'
cp dehydrated/certs/$HMAILSERVER_DOMAIN/privkey.pem $HMAILSERVER_DOMAIN.letsencrypt.key
cp dehydrated/certs/$HMAILSERVER_DOMAIN/fullchain.pem $HMAILSERVER_DOMAIN.letsencrypt.crt
chmod 777 ./hmailCert.sh
Openssl Create Server Certificate
hmailCert.bat
with the following content. NOTE: change the second line with the address of your script folder.set HMAILSERVER_DOMAIN='yourMXDomainNameLike_mail.mydomain.com'
cd c:UsersmyUserNameDocumentsNetworkinghmailserver_letsencryptbash -c './hmailCert.sh'
copy %HMAILSERVER_DOMAIN%.letsencrypt.key 'c:Program Files (x86)hMailServer'
copy %HMAILSERVER_DOMAIN%.letsencrypt.crt 'c:Program Files (x86)hMailServer'
net stop hMailServer
net start hMailServer
CMD
) as Administrator (right click on Command Prompt in the Windows 10 (start) menu and click Run as Administrator). Go to your script foldercd
c:UsersmyUserNameDocumentsNetworkinghmailserver_letsencrypt
hmailCert.bat
- Add the server's certificate (.crt) and the server's private key (.key) in Settings>Advanced>SSL Certificates.
- Set SMTP/POP3/IMAP to use the above SSL Certificate
- Settings>Advanced>TCP/IP Ports:
- SMTP: set Connection security to STARTLS (Optional), and then pick the SSL Certificate.
- POP3/IMAP: set Connection security to STARTLS (Required), and then pick the SSL Certificate
sudo apt-get install openssl curl sed grep mktemp git build-essential
sudo apt-get install python-dev curl libffi-dev libssl-dev python-pip
sudo easy_install pip
c:UsersmyUserNameDocumentsNetworkinghmailserver_letsencrypt
(change myUserName to your username). We will call this your script folder on this page.One-time initial setup
git clone https://github.com/lukas2511/dehydrated
cd dehydrated
mkdir hooks
git clone https://github.com/kappataumu/letsencrypt-cloudflare-hook hooks/cloudflare
sudo pip install -r hooks/cloudflare/requirements-python-2.txt
cd ..
Verisign Ssl Certificate
hmailCert.sh
by following:cat > ./hmailCert.sh
#!/bin/bash
export CF_EMAIL='yourCloudflareEmail@somedomain.com'
export CF_KEY='yourCloudflareAPIKey'
export HMAILSERVER_DOMAIN='yourMXDomainNameLike_mail.mydomain.com'
dehydrated -c -d $HMAILSERVER_DOMAIN -t dns-01 -k 'hooks/cloudflare/hook.py'
cp dehydrated/certs/$HMAILSERVER_DOMAIN/privkey.pem $HMAILSERVER_DOMAIN.letsencrypt.key
cp dehydrated/certs/$HMAILSERVER_DOMAIN/fullchain.pem $HMAILSERVER_DOMAIN.letsencrypt.crt
chmod 777 ./hmailCert.sh
Openssl Create Server Certificate
hmailCert.bat
with the following content. NOTE: change the second line with the address of your script folder.set HMAILSERVER_DOMAIN='yourMXDomainNameLike_mail.mydomain.com'
cd c:UsersmyUserNameDocumentsNetworkinghmailserver_letsencryptbash -c './hmailCert.sh'
copy %HMAILSERVER_DOMAIN%.letsencrypt.key 'c:Program Files (x86)hMailServer'
copy %HMAILSERVER_DOMAIN%.letsencrypt.crt 'c:Program Files (x86)hMailServer'
net stop hMailServer
net start hMailServer
CMD
) as Administrator (right click on Command Prompt in the Windows 10 (start) menu and click Run as Administrator). Go to your script foldercd
c:UsersmyUserNameDocumentsNetworkinghmailserver_letsencrypt
hmailCert.bat
- Add the server's certificate (.crt) and the server's private key (.key) in Settings>Advanced>SSL Certificates.
- Set SMTP/POP3/IMAP to use the above SSL Certificate
- Settings>Advanced>TCP/IP Ports:
- SMTP: set Connection security to STARTLS (Optional), and then pick the SSL Certificate.
- POP3/IMAP: set Connection security to STARTLS (Required), and then pick the SSL Certificate
net stop hMailServer
net start hMailServer
Automate Certificate Renewals
- General Tab:
- Run whether user is logged on or not (At the end when you click OK, it will ask you to enter windows credentials. Make sure to use an Admin account)
- Run with highest privileges
- Configure for: Windows 10
- Trigger
- Daily at some time every 85 days, Enabled
- Action
- Start a program
Program/script (update with your script folder): c:UsersmyUserNameDocumentsNetworkinghmailse
rver_letsencrypt/
hmailCert.bat
Start in: c:UsersmyUserNameDocumentsNetworkinghmailse
rver_letsencrypt
- Conditions
- Start the task only if the computer is idle for: 10 minutes
- Settings
- Allow task to be run on demand
- Run task as soon as possible after a scheduled start is missed
- Stop the task if it runs longer than 8 hours
- If the running task does not end when requested, force it to stop.