-   Linux - Newbie (
-   -   Command Line Send Mail (

nutthick 01-23-2005 10:53 AM

Command Line Send Mail
I'm just getting into bash scripting and am trying to get my script to email me with it's results. I'm on Slack 10, but without SendMail installed. At the moment I'm trying the following:

cat logfile.txt | mail -s "Subject - Log Results" ""

Bash accepts it, but obviously the mail never gets anywhere as there is no mail software running and I haven't given it an SMTP address. Is there any way of scripting to send an email through an external SMTP address? I don't want to install SendMail if possible.


jschiwal 01-23-2005 11:19 AM

If you are using Postfix, there is a sendmail program. It is a Postfix to Sendmail compatibility interface. This allows you to use the 'sendmail' command in scripts.

heema 01-23-2005 11:29 AM

sorry to ask another question in ur post but its related :)

i want the same thing also , isnt there a commandline mail client that u could set it up to use a pop3 mail instead ??

e.g. : i want to make a script , when if finishes it sends the result to me using my gmail account using a commandline mail program

is that possible ???

nutthick 01-23-2005 12:24 PM

thanks jschiwal, but what I'm looking for I guess is a scripting method that can do something like the following:

subject="Some Subject"

and then send it with something like command I posted earlier:

cat logfile.txt | mail -s $subject $send_to

Sorry if it's not clear what I mean, but I think heema and I are asking for the same thing.

nutthick 01-23-2005 03:17 PM

I've moved this post to the Programming forum.

heema 01-24-2005 03:46 AM

i may have found a solution but i havent tried it yet , its to use getmail and mutt

i found this site , its a howto for setting up getmail and mutt for pop usage

but i havent tried it yet as i am at work now :(

nutthick 01-24-2005 03:51 AM

heema - Let me know how you get on. I'm working on the SendMail solution.

nutthick 01-24-2005 10:43 AM

Well I got it all working in the end. I followed the following tutorial (not sure if I needed to or not, but it made good reading)

Then I used the following command to send the log file generated by the script

cat logfile.log | mail -s "Log Results" ""

HTH ;)

heema 01-24-2005 11:53 AM

I also made it to work but using an easy and different method (just what i wanted) ;)

i used nbSMTP (nbSMTP is a simple SMTP)
NOTE : u have to have openssl , libssl-dev installed

then i setup mutt (commandline mail program) by making a file named .muttrc in my HOME

here is mine :

set folder=~/Mail
folder-hook . "my_hdr From: <>"
set sendmail="/usr/local/bin/nbsmtp -U username -P password -d -h -f -p 587 -M p -S"

NOTE : ofcourse u have to enter ur username and password ;)

Then it worked :D

cat log.txt | mutt -s "Log Report"

jschiwal 01-24-2005 08:46 PM

Perhaps the post above provides the best answer.

Part of what you are missing is to use '--' so the rest of the arguments comes from standard input.

For example, I sent myself a file via an email to my local account with the line
sendmail jschiwal@localhost -- </etc/lilo.conf

If I had wanted to send it to my regular account, I would of used my ISP instead of localhost.

jschiwal 01-24-2005 08:52 PM

Sorry, Posted same message twice.

All times are GMT -5. The time now is 08:42 PM.