Wednesday, October 29, 2014

User nc to send smtp message in centos

nc is a handy tool in unix to test network connection and we can use it
to write script to send smtp message as well. It is useful when we
implement some kind of server monitoring scripts and want to send out
alarm messages.

In the example below, we use 'nc' to connect smtp-server at port 25 to
send out contents in email-msg.txt

#nc smtp-server 25 < email-msg.txt

The email-msg.txt contains the below commands to form the smtp dialogue.

#cat email-msg.txt
HELO my-server
Subject:This is a sample subject
This is a sample mnessage body

Note the last line of the message body is a line starting with '.'.

Another point to note is that if we create the email-msg.txt in unix
environment, we probably need to ensure each line ends by CRLF rather
than just a line feed.

To do so, we can simply use the unix2dos command:

#unix2dos email-msg.txt


  1. Thanks for sharing, nice post! Post really provice useful information!

    Giaonhan247 chuyên dịch vụ mua đồng hồ amazon với chia sẻ kinh nghiệm mua hàng trên Amazon và giải đáp mua hàng trên Amazon có đảm bảo không cũng như chia sẻ cách mua hàng trên ebay giúp các bạn mua hàng trên amazon vietnam uy tín nhất.

  2. Hi, I do believe this is a great blog. I stumbledupon it ;) I'm going to come back yet again since i have saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to help others. aol mail sign in