Postfix ProtonMail – Configure Postfix to Send Emails with ProtonMail Bridge

emailpostfixUbuntu

I have an Ubuntu 20.04 server and I followed this tutorial to install ProtonMail Bridge :

https://pychao.com/2020/06/10/update-on-using-protonmail-bridge-on-headless-wordpress-linux-servers/

The reason ProtonMail users require this extra utility is that, for
outbound emails, ProtonMail encrypts users’ email content before
handing over the email to the sending server. And for inbound emails,
ProtonMail decrypts the email contents for users after downloading the
emails, and so when users open the incoming emails, the contents are
readable. While using ProtonMail’s online interface, everything is
done behind the scene. Users just write/read emails as they do on
Gmail, etc. But if users want to use offline email clients on their
local machines, then those clients lack the functionality of
encrypting/decrypting the emails before/after doing communications
with ProtonMail’s servers (see note 1). That’s why ProtonMail provides
a utility called Bridge.

In a nutshell, ProtonMail Bridge creates fake IMAP/SMTP servers on the
local machine. And users use these fake local servers for the
IMAP/SMTP settings in their offline email clients. When offline
clients try to do communications with email servers, they are in fact
communicating with the fake local servers. And next, the local servers
do the encryption/decryption tasks and then talk to the real
ProtonMail servers.

For more details, please read the introductions at ProtonMai Bridge.
This post does not intend to deal with the usage of Bridge. Instead,
this post tries to deal with an issue that occurs when using Bridge in
headless (i.e., not connected to any physical monitors) Linux
environments.

I have a Drupal 8 site on my server and it is sending emails correctly with ProtonMail Bridge.

Now I want Postfix to use ProtonMail Bridge to send server emails (Logwatch, Monit, …).

I followed the following tutorial to install and configure Postfix :

https://devanswers.co/configure-postfix-to-use-gmail-smtp-on-ubuntu-16-04-digitalocean-droplet/

Here is my configuration

Install Postfix

$ sudo apt install postfix

Enter the domain mydomain.com at "System mail name" and leave the rest by default

Configure Postfix

$ sudo nano /etc/postfix/main.cf

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = ov-hjhjhjhj.kjkjkjj.ch
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mydomaine.com, ov-b2bbd0.infomaniak.ch, localhost.infomaniak.ch, localhost
relayhost = [127.0.0.1]:1025
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

Create the sasl_passwd file to store the credentials

$ sudo nano /etc/postfix/sasl_passwd

[127.0.0.1]:1025 contact@mydomaine.com:password

Use information in ProtonMail Bridge

Create a hash database file

$ sudo postmap /etc/postfix/sasl_passwd

Secure credentials

$ sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
$ sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Restart Postfix

$ sudo systemctl restart postfix

Check status Postfix

$ sudo systemctl status postfix

Install mailutils

$ sudo apt install mailutils

Test sending email

$ echo "Contenu du mail" | mail -s "Titre du mail" contact@mydomaine2.fr -aFrom:contact@mydomaine.com

The problem is that I am not receiving any email and there is no error message. What is wrong with my setup ?

Here is the Drupal 8 configuration that works :

enter image description here

Best Answer

You have omitted the lines telling postfix to authenticate when sending mail, which were in the postfix tutorial you cited. Thus your sasl_passwd file is ignored.

At least you should have

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

if these are not already in master.cf. However, you should reproduce the relevant lines from the mail log to accurately diagnose the problem, otherwise everything is guesswork.