LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command Line Send Mail (http://www.linuxquestions.org/questions/linux-newbie-8/command-line-send-mail-281203/)

nutthick 01-23-2005 09: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" "name@mailserver.com"

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.

Thanks

jschiwal 01-23-2005 10: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 10: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 11:24 AM

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

smtp_server="smtp.somemailserver.com"
send_to="me@myaddress.com"
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 02:17 PM

I've moved this post to the Programming forum.

heema 01-24-2005 02: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

http://home.nyc.rr.com/computertaijutsu/mutt.html

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

nutthick 01-24-2005 02:51 AM

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

nutthick 01-24-2005 09: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)

http://www.linuxquestions.org/questi...postid=1144362

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

cat logfile.log | mail -s "Log Results" "me@myemail.com"

HTH ;)

heema 01-24-2005 10: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

http://nbsmtp.ferdyx.org/

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: <username@gmail.com>"
set sendmail="/usr/local/bin/nbsmtp -U username -P password -d gmail.com -h smtp.gmail.com -f username@gmail.com -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" username@gmail.com

jschiwal 01-24-2005 07: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 07:52 PM

Sorry, Posted same message twice.


All times are GMT -5. The time now is 12:01 PM.