Send Mail from SUSE Linux(Gmail)
Mail from SUSE Linux to Gmail
In this, we will use Postfix as our MTA (mail transfer agent).
Postfix is a free, open-source, actively maintained, and highly secure mail transfer agent.
Make sure port 25 and 587 is open or not.
In December of 1998, R. Gellens and J. Klensin submitted RFC 2476 in support of adding a new specification for internet email communications. The RFC proposed a split of the traditional massage submission and message relay concept. The RFC defined that message submission should occur over port 587 to ensure new policy and security requirements don't interfere with the traditional relay traffic over message relay port 25.
Note: All commands require root privileges.
1. Install Required Software
zypper update && zypper install postfix mailx cyrus-sasl
for other Linux flavor, we can change the word zypper with the respected installer
Note: Be sure with the administrator before updating…...
if your system is already updated just execute.
zypper install postfix mailx cyrus-sasl
2. Configure Gmail Authentication
Create or modify a password file that will be used by Postfix to establish authentication with Gmail. In the authentication information below, replace the username with your Gmail username and password with your Gmail password. If you are using a custom Gmail Apps domain name, you may replace gmail.com with your Google Apps domain.
The password file will reside in the Postfix configuration directory. The file can be named whatever you like, but the recommended filename is sasl_passwd.
Postfix configuration files reside in the directory /etc/postfix.
vim /etc/postfix/sasl_passwd
In this, I used vim file editor if u can use any other file editors also
[smtp.gmail.com]:587 username@gmail.com:password
replace the username with your Gmail username and the password with your Gmail password.
Save and close the file. Your Gmail password is stored as plaintext, so make the file accessible only by root:
chmod 600 /etc/postfix/sasl_passwd
for the above command will change the file permeation to only by root/user
3. Configure Postfix
There are six parameters which must be set in the Postfix configuration file: main.cf. The parameters are:
relayhost
smtp_use_tls
smtp_sasl_auth_enable
smtp_sasl_security_options
smtp_sasl_password_maps
smtp_tls_CAfile
Edit the main Postfix configuration file:
vim /etc/postfix/main.cf
modify the following values:
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/ca-bundle.pem
Save and close the file.
It also requires that the Postfix master process configuration file master.cf be modified. Open it for editing:
vim /etc/postfix/master.cf
Locate the line below:
#tlsmgr unix - - n 1000? 1 tlsmgr
Uncomment it:
tlsmgr unix - - n 1000? 1 tlsmgr
Save and close the file.
4. Process Password File
postmap /etc/postfix/sasl_passwd
Then check it out /etc/postfix for the sasl_passwd.db file whether it was created or not.
5. Restart Postfix
systemctl restart postfix.service
for some version, this will works
postfix stop && postfix start
6. Enable "Less Secure Apps" In Gmail
You want to enable and disable settings refer to link
https://support.google.com/accounts/answer/6010255
7. Send A Email
mail -s "Test subject" recipient@domain.com
You will be presented with a blank line (or a CC: field, which you can bypass by pressing Enter). Type the body of your message, pressing Enter for new lines. When you are finished composing the email, type CTRL-D to send it. To cancel the email, press CTRL-C twice.
To send a precomposed email, use the command:
mail -s "Subject Here" recipient@domain.com < textfile
Troubleshooting
If it's not working, check the logs for any Postfix errors:
journalctl
If you receive authentication errors from Gmail:
verify that Allow Less Secure Apps is turned on in your Gmail account settings
Verify that the password file sasl_passwd exists and its contents are containing the correct information
restart Postfix.
If you see any TLS errors :
check the configuration in main.cf
If you make any configuration changes, restart Postfix
If u get any unreachable errors:
1.ensure the internet service provider(ISP) is allowing or blocking the service.
2.check the iptables outbound rules if any port is blocked by the iptable.
Comments
Post a Comment