Installing and configuring Postfix with Gmail SMTP on Raspbian

Installing packages:

sudo apt-get install postfix

Configuring Postfix:
– choose “satellite system”
– system mail name = computername

Edit Postfix config file:

sudo nano /etc/postfix/main.cf

and add the following:

#smtp_use_tls = yes #needed on ubuntu
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
smtp_tls_security_level = may

Providing authentication details by editing this file:

sudo nano /etc/postfix/sasl_password

and adding:

[smtp.gmail.com]:587 username@gmail.com:password

Secure the file with:

sudo chmod 600 /etc/postfix/sasl_password

and generate the database for it:

sudo postmap hash:/etc/postfix/sasl_password

Restarting Postfix and sending a test mail:

sudo service postfix restart
echo "test" | mailx -s "test" destination@mail.com

You can also send a mail with attachment using mpack:

mpack -d yourmessagebody.txt -s "subject" file destination@mail.com