postal icon indicating copy to clipboard operation
postal copied to clipboard

How to Configure SSL on the Web and SMTP?

Open moskoweb opened this issue 8 years ago • 11 comments

I have read some of the already open posts on this subject, but I have not yet been able to properly enable SSL on the Web.

And I would also like to enable SSL on the SMTP server.

Any tutorial or easy to understand method?

moskoweb avatar Feb 01 '18 17:02 moskoweb

SSL for click tracking is handled by Postal but if you want SSL for the web ui and SMTP, you'll have to get your own certificate.

The easiest way is to use certbot and the webroot method with something like this:

certbot certonly --webroot --webroot-path /opt/postal/app/public --domains postal.yourorganisation.com

Certbot will tell you where the certificate is located and then you can specify that in your nginx configuration and postal.yml

Nginx:

ssl_certificate     /etc/letsencrypt/live/postal.yourorganisation.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/postal.yourorganisation.com/privkey.pem;

Postal:

smtp_server:
  tls_enabled: true
  tls_certificate_path: /etc/letsencrypt/live/postal.yourorganisation.com/fullchain.pem
  tls_private_key_path: /etc/letsencrypt/live/postal.yourorganisation.com/privkey.pem

Certbot will automatically renew the certificates so you don't have to worry about replacing them yourself. If you have your own certificate from another source, you can upload it to your server and specify the paths to it like the above.

willpower232 avatar Feb 03 '18 11:02 willpower232

Ooohh, thanks, it's working perfectly.

moskoweb avatar Feb 06 '18 00:02 moskoweb

In case it helps someone looking at this: it took me some time to figure out that the nginx configuration referenced above happens in /etc/nginx/sites-available/default . Update the hostname in there too.

timraybould avatar Jan 25 '19 21:01 timraybould

FYI, my certs renewed nicely with this method, however, I had to manually reload nginx via sudo systemctl reload nginx to get it to "see" the new cert after renewal.

timraybould avatar Apr 26 '19 19:04 timraybould

If you're using certbot and its default automatic renewal method, I guess certbot will reload nginx.

shinebayar-g avatar Apr 27 '19 04:04 shinebayar-g

In our experience, the cron job that certbot uses to generate the new certificates doesn't reload the services by default but adding in the necessary && systemctl reload ... to /etc/cron.d/certbot isn't a big task.

We also use certbot directly from pip to access some plugins which means the cron file doesn't get created so thats another reason to manage the cron file yourself.

willpower232 avatar Apr 29 '19 09:04 willpower232

facing problem in 2022. i think the path of public folder is different now. what can be done?

The-3x avatar Mar 22 '22 03:03 The-3x

@The-3x same, I will try to solve it by using dns as challenge option instead of .well-known url

lucacastelnuovo avatar Aug 05 '22 16:08 lucacastelnuovo

I tried the following, but it, unfortunately, did not work.

My steps

  1. run sudo certbot certonly --manual --preferred-challenges dns -d "postal.example.com"

  2. mkdir /opt/postal/config/certs

  3. ln -s /etc/letsencrypt/live/postal.example.com/privkey.pem /opt/postal/config/certs/privkey.pem

  4. ln -s /etc/letsencrypt/live/postal.example.com/fullchain.pem /opt/postal/config/certs/fullchain.pem

  5. edit /opt/postal/config/postal.yml

smtp_server:
  port: 25
  tls_enabled: true
  tls_certificate_path: config/certs/fullchain.pem
  tls_private_key_path: config/certs/privkey.pem
  1. postal stop
  2. postal start

The error Errno::ENOENT: No such file or directory @ rb_sysopen - config/certs/fullchain.pem

This didn't work because my misunderstanding of ln. I thought the contents of the files would be passed to the container. but in reality the symlink was passed which didn't resolve (naturally).

My solution can be found here: https://github.com/Luca-Castelnuovo/mail.ltc.

lucacastelnuovo avatar Aug 05 '22 16:08 lucacastelnuovo

I tried the following, it unfortunately didn't work.

My steps

  1. run sudo certbot certonly --manual --preferred-challenges dns -d "postal.example.com"
  2. mkdir /opt/postal/config/certs
  3. ln -s /etc/letsencrypt/live/postal.example.com/privkey.pem /opt/postal/config/certs/privkey.pem
  4. ln -s /etc/letsencrypt/live/postal.example.com/fullchain.pem /opt/postal/config/certs/fullchain.pem
  5. edit /opt/postal/config/postal.yml
smtp_server:
  port: 25
  tls_enabled: true
  tls_certificate_path: config/certs/fullchain.pem
  tls_private_key_path: config/certs/privkey.pem
  1. postal stop
  2. postal start

The error Errno::ENOENT: No such file or directory @ rb_sysopen - config/certs/fullchain.pem

How did you fix Errno::ENOENT: No such file or directory @ rb_sysopen - config/certs/fullchain.pem ?

j-p9 avatar Dec 06 '22 03:12 j-p9

You can see my solution here: https://github.com/Luca-Castelnuovo/mail.ltc/blob/main/README.md

lucacastelnuovo avatar Dec 18 '22 18:12 lucacastelnuovo