Sending an Email Using Shell
In this post I will introduce you about sending an email by using terminal, as sending an email via graphical MTA can be cumbersome.:) To send an email on shell terminal, I will use ssmtp which sends mails local computer to configured mail hub. It is not mail server such as postfix. Ssmtp package exists in epel-repo, so you need to add epel-repo, if you do not already add it. Install Epel Repo:
#yum install epel-release
Install SSMTP:
#yum install ssmtp
After Installing ssmtp you need to configure files on /etc/ssmtp/ folder. There are two configuration files in /etc/ssmtp folder. ssmtp.conf file is actual configuration file that you add your mail account information. revealiases file is used for reverse mail aliases. Configuration of SSMTP Open ssmtp.conf file with your favourite text editor and write down below configuration on end of the file and change it with your own account information. You can see my configuration.(Figure-1) Figure-1(ssmtp.conf)
Testing Time: Actually when I test it without configuring revealiases(reverse mail alias file) I got an error because of my local domain which is tbag.local. You can see below it MAIL FROM section.(Figure-2). I tried to send an email on verbose mode. To solve the problem you also need to configure revealiases file (Figure3). Add your user and mail domain like below. After configuration of revealiases, I am able to send an email successfully.(Figure-4)
ssmtp -v [email protected]
Hello world !
[<-] 220 smtp.mail.yahoo.com ESMTP ready
[->] EHLO dns.tbag.local
[<-] 250 STARTTLS
[->] STARTTLS
[<-] 220 2.0.0 Start TLS
[->] EHLO dns.tbag.local
[<-] 250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE
[->] AUTH LOGIN
[<-] 334 VXNlcm5hbWU8
[->] c2VuZG1lbWVsb25AeWFob28uTv42
[<-] 334 UGFzc3cvctQ6
[<-] 235 2.0.0 OK
[->] MAIL FROM:<[email protected]>
[<-] 553 From address not verified - see http://help.yahoo.com/l/us/yahoo/mail/original/manage/sendfrom-07.html
ssmtp: 553 From address not verified - see http://help.yahoo.com/l/us/yahoo/mail/original/manage/sendfrom-07.html
Figure-2 (Error while sending an email)
root:[email protected]:smtp.mail.yahoo.com:587
demo:[email protected]:smtp.mail.yahoo.com:587
Figure-3 (revealiases)
[root@dns ssmtp]# ssmtp -v [email protected]
Hello World !
[<-] 220 smtp.mail.yahoo.com ESMTP ready
[->] EHLO dns.tbag.local
[<-] 250 STARTTLS
[->] STARTTLS
[<-] 220 2.0.0 Start TLS
[->] EHLO dns.tbag.local
[<-] 250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE
[->] AUTH LOGIN
[<-] 334 VXNpnx5hlWU9
[->] c2VuZG1lbWVsb25AetGob32uY29m
[<-] 334 UGFzc3uvcmQ6
[<-] 235 2.0.0 OK
[->] MAIL FROM:<[email protected]>
[<-] 250 OK , completed
[->] RCPT TO:<[email protected]>
[<-] 250 OK , completed
[->] DATA
[<-] 354 Start Mail. End with CRLF.CRLF
[->] Received: by dns.tbag.local (sSMTP sendmail emulation); Fri, 10 Mar 2017 01:40:30 +0300
[->] From: "root" <[email protected]>
[->] Date: Fri, 10 Mar 2017 01:40:30 +0300
[->] Hello World !
[->]
[->] .
[<-] 250 OK , completed
[->] QUIT
[<-] 221 Service Closing transmission
Figure-4(Sending an email)
One more thing! Mai
l providers such as gmail, yahoo prohibit sending an email by some third party applications such as ssmtp, sendmail etc. To allow sending an email such applications, you should turn on less secure sign-in property. For yahoo you can do that on the Account Security tab.(Figure-5)
Figure-5(Turning on less secure sign-in for yahoo)