[Tutorial] [Files] [Photos] How to be able to send mail from a self-hosted Cozy using a Postfix relayhost


#1

Hello all,

Following this thread, here is a short tutorial to set up a Postfix relayhost and be able to send emails when sharing from Files and Photos on a self-hosted system. It is mostly inspired from this tutorial and this one.

Prerequisites:

  • having admin rights on your server
  • having Postfix installed on your server
  • having the details of the SMTP server you want to use (URL, port and credentials)
  • First step: setting up Postfix main configuration file

Create a back-up of your config file:

cp /etc/postfix/main.cf /etc/postfix/main.cf.bak

Open the Postfix main configuration file with admin rights:

vim /etc/postfix/main.cf

Find and change or add the following lines:

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
smtp_always_send_ehlo = yes
relayhost = smtp.yourdomain.tld

replacing smtp.yourdomain.tld by the SMTP server you want to use. If you need to mention the port you want to contact, enter it like this:

relayhost = [smtp.yourdomain.tld]:PORT

  • Second step: enter the credentials for your SMTP server

Open/create the file you mentioned in the config file:

vim /etc/postfix/saslpasswd

Add your credentials in this format (with a tab between the two blocks, I don’t know how to display it here):

smtp.yourdomain.tld yourlogin:yourpassword

Change the permissions of this file so that only the root user can access it:

chown root:root /etc/postfix/saslpasswd
chmod 600 /etc/postfix/saslpasswd

Finally, convert it in a format Postfix can read:

postmap /etc/postfix/saslpasswd

  • Restart Postfix

service postfix restart

And you should be good to go!


Handling how Cozy sends email on self-hosted systems
Portage de Cozy sur OpenWRT
Ubuntu 16.04
Passwort zurücksetzen
#2

Thanks a lot for this tutorial! I’ve tried it and it works very well.

There is just a small typo. For chown and chroot, the filename has no _:

chown root:root /etc/postfix/saslpasswd
chmod 600 /etc/postfix/saslpasswd

#3

Oops, thanks for spotting this I’ll change it right away!


#4

Thanks a bunch @rouky for this tutorial, was looking for a way to do this without having to set up an entire mail server. I’m going to try it out tonight on some self-hosted instances of mine :smile:


#5

Works for me too.
(self hosted: ubuntu in a VirtualBox)
Thanks a lot!


#6

@rouky For the record, I linked you tutorial in our documentation: http://docs.cozy.io/en/host/troubleshooting.html#my-server-is-unable-to-send-emails

Thanks again for your kind contribution :smile:


#7

Thanks @rouky, this works very well.
I just had to make a small change recently:
I changed relayhost = smtp.yourdomain.tld
to relayhost = [smtp.yourdomain.tld]
Because postfix was checking for MX-type DNS entry for smtp.yourdomain.tld . The [] tells postfix not to do such