Send email through linux console

Hi All,

I have a log file that need to be sent to an email address.

I've tried this script :

echo "This is mail body" | mail -s "This is subject"

It give me nothing.

Could you provide step by step to configure my linux server so I could send email, and also provide me the script.

A link to other forum would  be fine, if it give clear and detailed information
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

#/etc/init.d/sendmail status

It might be possible that it is not running.

#/etc/init.d/sendmail restart

Hopefully,your mail would be on its way at your mailbox.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Try something like this in bash:

cat - file.log << EOF | sendmail -t
subject:Log File

You should first have a look at the maillog to see what happened. There are numerous reasons for the failure of a mail.
The logs you'll find under /var/log.

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Being somewhat a novice at this myself, I used a simple perl script that someone wrote called sendEmail.  It will use an alternate SMTP connection. It is quick to setup, simplified instructions here:

Original source, with examples.
In my testing and quick learning curve with it, I was able to emails with attachments.
if you are asking this not for any programming use.. then i would suggest you check out pine

If you wish to send the log file in the body of the mail itself then use following command

mail -s "Log file" < log-file.log

And if you wish to send it as attachment then you must have a mutt installed on your system if not grab then

# yum install mutt

Or download rpm of mutt from net and install manually as follows

# rpm -ivh mutt-<version>.rpm

Now create a file having body contents of the mail ( im considering  /tmp/body.txt in following eg.)

mutt -s "Log file" -a /path/to/logfile.log < /tmp/body.txt

softblessAuthor Commented:
Hi Guys,

Please response :
@savone, I've tried :
cat - config.txt << EOF | sendmail -t
subject:Log File
It doesn't give error message when I execute it, but I don't receive the email

The same thing goes to commands that was given by @ajay

@hemmi, i cannot understand the log.

I'll attach the mailloh in this post.

@c_a_n_o_n I've tried installing the sendEmail, but I got error message. If I use this commad :
sendEmail -f -t \
-u this is the test tile -m “this is a test message” \
-s \
-o tls=auto \
-xu -xp mygmailpassword
The error message will be :
Apr 07 08:34:45 localhost sendEmail[5476]: NOTICE => Authentication not supported by the remote SMTP server!
Apr 07 08:34:46 localhost sendEmail[5476]: ERROR => Received:       530 5.7.0 Must issue a STARTTLS command first. v26sm7259924qce.13

and If I use this command :
sendEmail -f -t \
-u this is the test tile -m “this is a test message” \
-s \
-o tls=yes \
-xu -xp mygmailpassword

the error message will be :
Apr 07 08:38:40 localhost sendEmail[5601]: ERROR => No TLS support!  SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)

Please kindly response... thank you.
LinuxGuruLinux Server AdministratorCommented:

Could you please try installing the TLS Support?

Starting with sendEmail v1.54, TLS support is included! To enable TLS support simply install the Net::SSLeay and IO::Socket::SSL perl modules. The following new command line parameters are now available:
    -o tls=auto This is the default, TLS will be used if possible.
    -o tls=yes Use this to require TLS for message delivery.
    -o tls=no Use this to disable TLS support.
If TLS is giving strange errors, try upgrading the Net::SSLeay and IO::Socket::SSL perl modules.

Please refer the following link.
Dave BaldwinFixer of ProblemsCommented:
Sending email to Yahoo can be difficult.  They block a lot of things.  The fact that your From address isn't going to match your server address may make it harder also.  Do you have other email addresses that you can use?  For test purposes, it would be nice if they Didn't have spam blocking.

I think I would first get a standard email program working on your server to make sure that works.
softblessAuthor Commented:
@testez, could you give command to install the Net::SSLeay and IO::Socket::SSL perl modules?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Networking

From novice to tech pro — start learning today.