It can be very convenient, for those who use services such as zoneminder, rtorrent, etc., to have a “Gmail Relay” to send maisl from your Gmail account.
In this guide we will see how to configure postfix to send email with our account [email protected]
The guide is based on ArchLinux, but apart the installation of the packages, the configuration is the same also on other distributions such as Debian or Centos.
As first thing we need to install the packages with :
$ sudo pacman -Sy postfix ca-certificates
Once the installation is complete go into the directory where postfix keep its configuration files :
$ cd /etc/postfix
And do a copy of the default configuration, just to be sure.
$ sudo cp main.cf main.cf-old
Now open the file
main.cf with your favorite editor and delete everything (with vi just type
1000 dd and copy this configuration:
daemon_directory = /usr/lib/postfix myorigin = myrealdomain.com # substitute myrealdomain.com with your domain name mydomain = myrealdomain.com myhostname = myrealdomain.com smtp_generic_maps = hash:/etc/postfix/generic header_checks = regexp:/etc/postfix/header_checks relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd_gmail smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_use_tls = yes smtp_tls_security_level = encrypt smtp_enforce_tls = yes disable_dns_lookups = yes message_size_limit = 35651584 smtp_destination_rate_delay = 60 relay_destination_rate_delay = 60 mynetworks = 127.0.0.1 alias_maps = hash:/etc/aliases
Save the file as main.cf and don’t forget to substitute myrealdomain.com with your real domain name, for me this would be linuxaria.com.
Now create the file /etc/postfix/sasl_passwd_gmail with your favorite editor and insert in it this line:
username with your real username and
mypassword with your real password.
Now add at the end of the file /etc/postfix/header_checks the following lines:
/^To:.*@hostname.localnet/ REDIRECT email@example.com /^From:(.*@myrealdomain.com[>]*)/ PREPEND Reply-To:$1
As usual substitute
username with your real username and
myrealdomain with your real domain name already used in the file main.cf.
Now add at the end of the file /etc/postfix/generic the following lines:
firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com
Guess what ?
Yes you have to substitute as usual
Now open a terminal as root and run these commands:
$ postmap /etc/postfix/generic $ postmap /etc/postfix/sasl_passwd_gmail $ cat /etc/ssl/certs/Equifax_Secure_CA.pem >/etc/postfix/cacert.pem $ ln -s /etc/postfix/aliases.db /etc/aliases.db $ postconf -e alias_maps=hash:/etc/aliases
Start postfix with the command:
$ systemctl start postfix
Enable it at boot time with the command:
$ systemctl enable postfix
At this point, we can test the whole configuration by sending an email with the following command:
$ echo "body of the message" | mail -r "[email protected]" -s "Subject of the mail" firstname.lastname@example.org
This command will send a mailwith from [email protected] to [email protected] directly from your ArchLinux.
To verify the correct transmission we can at any time view the log located at /var/log/mail.log and keep track of sent emails.
If you want to send mail remotely, for example from another PC of the same network, you first need to put in the file main.cf in the directive
mynetworks the cilent ip, this will enable it to use this machine as relay, restart postfix and on the client issue the command:
$ echo "body of the message" | mail -r "[email protected]" -s "Subject of the mail" -S smtp=IPPOSTFIX email@example.com
Replacing “IPPOSTFIX” with the IP of the machine where we have configured postfix.
If you want to enable an entire network, it is possible to include in the directive
mynetworks the entire subnet, eg 192.168.0.0/24.
- None Found
Find me on Google+