Jan 26, 2014

Minimal configurations for sending mails using the terminal


This is something I came across while I was doing the performance test for our ESB. Performance test for the ESB took some time and had some output files. I wanted this output files after each iteration. However, It is not good to longing to the machine while the performance test is on going. Therefore, I wanted a notification system to notify me and send the files after each iteration. In order to archive this I used mails with attachments.

Like this there could be many scenarios where you have to send mails as a notification. This blog post shows how to configure and send mail using the terminal withing minutes.

MSMTP as the MSA (Message Sending Agent)

First thing we need to do is installing and configuring a MSA. For this I have chosen msmtp. Issue the following command to install msmtp.

sudo apt-get install msmtp

Then configure it to send mails. In my case I have used gamil for sending mails. In order to configure it first you need to change permission of the file ~/.msmtprc. To do this issue the following commands.

touch ~/.msmtprc
chmod 0600 ~/.msmtprc

Now you can configure it for sending mail with gmail as follows.

# Use an external SMTP server with insecure authentication.
# (manually choose an insecure authentication method.)
# Note that the password contains blanks.
defaults
######################################################################
# A sample configuration using Gmail
######################################################################
# account name is "gmail".
# You can select this account by using "-a gmail" in your command line.
account gmail
host smtp.gmail.com
tls on
tls_certcheck off
port 587
auth login
from <your gmail address>
user <username (I normally use the from value for this)>
password <password>
# If you don't use any "-a" parameter in your command line,
# the default account "someplace" will be used.
account default: gmail

Mutt as the mail sender

Though we can use msmtp to send mails, it is better to use something like mutt because it provides convenient options when your sending a mail such as sending attachments. However, mutt itself could not send mails. It needs a MSA such as msmtp.

Let's install mutt first.

sudo apt-get install mutt

Then configure it to use msmtp as its MSA.

vim ~/.muttrc
set sendmail="/usr/bin/msmtp"
set from=<your gmail address>

That's it. You are ready to go. Now issue the following command to test sending mails with attachments. 

echo "body." | mutt -d 1 -s "attachment" aaa@bbb.com -a abc.zip

Replace aaa@bbb.com and abc.zip as you wish and hit enter. There should be a mail in the destination mail with the subject attachment. 



1 comment :


  1. Shop from any USA online stores and Ship to your Doorstep anywhere in the world. We provide Free USA Address so you can shop from USA and Ship Internationally.
    shop and ship
    myus
    us forwarding address

    ReplyDelete

    Blogger news

    Blogger templates

    Blogroll

    About