In the Global word, we always want to keep connect to everyone. To accomplish this email is also a very popular method to send and receive information. Linux systems also provide tools to send emails from the command line which is useful to get system details, to send emails from shell scripts etc.
When we simply send email from Linux terminal, email sends as system [email protected] Some of the SMTP servers can block these emails or mark them as spam. So we need a process which maximizes the email delivery to the inbox. Using this article we are configuring our server to send email from SMTP servers like Gmail, Amazon SES etc. This article will help you setup SSMTP server and send email through Gmail servers.
Step 1: Install SSMTP Server
SSMTP service packages are available under EPEL repository, So make you have EPEL yum repository configured in your system.
[[email protected] ~]#yum install ssmtp
Step 2: Configure SSMTP
Now edit SSMTP configuration file and add following values. In this article, I am using Gmail SMTP server. If you also want to setup with Gmail, make sure you have an email account with Gmail.
[[email protected] ~]#vim /etc/ssmtp/ssmtp.conf
Change following values in configuration file
mailhub=smtp.gmail.com:587 UseSTARTTLS=YES [email protected] AuthPass=XXXXXXXXXXXXXXX TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
mailhub: you smtp server host/ip with port.
UseSTARTTLS: Set it Yes if SMTP server uses TLS else No.
AuthUser: Use Gmail ID here
AuthPass: Use Gmail ID’s password
TLS_CA_File: This may required some time, If you face issue like “send-mail: Cannot open smtp.gmail.com:587”
Step 3: Send Test Email
Now test the setup by sending a test email to your own email address, to send email use following command.
[[email protected] ~]#ssmtp [email protected] Subject: This is Subject Line Email content line 1 Email content line 2 Email content line 3 ^d
To send email press button CTRL+d (^d). Now check your mailbox.
Step 4: Setup SSMTP as Default
Now set SSMTP as your default mail server, So that you can simply use mail command to send emails through SSMTP.
[[email protected] ~]#alternatives --config mta There are 2 programs which provide 'mta'. Selection Command ----------------------------------------------- 1 /usr/sbin/sendmail.ssmtp *+ 2 /usr/sbin/sendmail.sendmail Enter to keep the current selection[+], or type selection number: 1
Verify the changes by
[[email protected] ~]#sendmail -V sSMTP 2.61 (Not sendmail at all)