In the Global word, we always want to keep connected 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 used 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.
yum install ssmtp
Step 2 – Configure SSMTP
Now edit SSMTP configuration file and add the following values. For this tutorial, I am using the Gmail SMTP server. If you also want to set up with Gmail, make sure you have an email account with Gmail.
vim /etc/ssmtp/ssmtp.conf
Change the following values in the configuration file
mailhub=smtp.gmail.com:587 UseSTARTTLS=YES [email protected] AuthPass=XXXXXXXXXXXXXXX TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
The above details are as followings,
- mailhub: your 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 an email address. First compose the mail in text file like:
vim msg.txt
Add email content, for example:
Subject: This is Subject Line Email content line 1 Email content line 2
Then send email to “[email protected]” using the ssmtp command:
ssmtp [email protected] < msg.txt
Let's check your mailbox for the new email.
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.
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
sendmail -V sSMTP 2.61 (Not sendmail at all)
Smtp configure in Linux cell manager
ssmtp: 530 5.7.0 Must issue a STARTTLS command first. a6sm7530382pgb.34 – gsmtp
why does this error kept coming?
Hello,
I tried mailing using SSMTP and mailutils even.But both resulted me an error saying “Cannot open smtp.gmail.com:587″ and ” Process exited with a non-zero status”.
I have been trying for past 3 days to get this right but failed everytime. I tried by adding TLS_CA_FILE… command in config file too but it has also gone in vain.
Please provide me a solution
Thnaks in advance
hello,
i am working on writing a script to send the email.
is there any solution to use, instead of “^d” to make it work in a script.
thanks
Hello,
just configured ssmtp following Rahul’s helpful instructions – immidiate success!
Now I have the same question as you:
Is there any solution to use, instead of “^d” to make it work in a script?
If you found such a solution it would be nice to read about it.
Thank you in advance
Hi HAYTHEM & RUDOLF,
I have updated the Step 3 in the tutorial. Hope this will help you to send emails via script.
Currently I’m using Nextehost.com SMTP but planning to build own server for Email marketing. hope this will be more cheaper.
suggest me what I need ? I send 10k-15K email on alternate days.
Hi Rohit, You can use Postal SMTP server.
https://tecadmin.net/install-postal-mail-server-on-ubuntu/
Nice tutorial!
plz provide me soln.
I solved this by allowing google to accept connections from untrusted/not safe apps in this module: https://www.google.com/settings/security/lesssecureapps
Of course be careful when activating this!
ssmtp: Authorization failed (534 5.7.14 https://support.google.com/mail/answer/78754 as4sm18579248pbc.48 – gsmtp)
Thanks for the great write-up. Do you know what the syntax looks like to send to multiple recipients from the command line?
I’ve tried adding Cc: in a separate text file and doing ssmtp [email protected] < message.txt
but it looks like this just makes it appear like the other recipients were CC'd, without actually sending the message to them.
Hello,
When i run this command # vim i got this
VIM – Vi IMproved
~
~ version 7.2.411
~ by Bram Moolenaar et al.
~ Modified by
~ Vim is open source and freely distributable
~
~ Help poor children in Uganda!
~ type :help iccf for information
~
~ type :q to exit
~ type :help or for on-line help
~ type :help version7 for version info
which is different from your next Step what is wrong?
Hope to help
You will probably have an easier time if you use nano as your editor instead of vim.