LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-23-2005, 09:53 AM   #1
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Rep: Reputation: 30
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
 
Old 01-23-2005, 10:19 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
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.
 
Old 01-23-2005, 10:29 AM   #3
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
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 ???
 
Old 01-23-2005, 11:24 AM   #4
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
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.

Last edited by nutthick; 01-23-2005 at 11:25 AM.
 
Old 01-23-2005, 02:17 PM   #5
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
I've moved this post to the Programming forum.
 
Old 01-24-2005, 02:46 AM   #6
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
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
 
Old 01-24-2005, 02:51 AM   #7
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
heema - Let me know how you get on. I'm working on the SendMail solution.
 
Old 01-24-2005, 09:43 AM   #8
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
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
 
Old 01-24-2005, 10:53 AM   #9
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
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

cat log.txt | mutt -s "Log Report" username@gmail.com
 
Old 01-24-2005, 07:46 PM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
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.
 
Old 01-24-2005, 07:52 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
Sorry, Posted same message twice.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send mail from command line buskmann Linux - Newbie 7 07-23-2006 10:18 PM
Send HTML mail via command line interface xlash Linux - General 2 11-02-2005 01:02 PM
can i send mail from command line? iflorea Linux - Software 6 11-02-2005 07:08 AM
Cannot send mail with mail() command in PHP 4.3.4, Apache 2.0.48, Mandrake Linux 10 arcanum Linux - General 3 06-27-2004 06:06 PM
internet line down, cant send mail internally. dashburner Linux - Networking 1 11-12-2003 12:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration