LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-22-2005, 12:07 PM   #1
Utah
Member
 
Registered: Apr 2004
Distribution: Fedora Core 3
Posts: 73

Rep: Reputation: 15
Cron mail sending using outside SMTP mail server


I have a very simple (for someone who understands mail) mailing problem:

I want to write a cron job to periodically automatically send a short email to one address.

For everyday email, I'm using Evolution on my Fedora Core 3 box and I have it set up to use my ISP's SMTP mail server for outgoing mail. It works fine.

How can I do the same thing from a script or cron job?

Do I need a mail server running on my machine? It appears that sendmail is running but I think it's there just so root and other local users can get mail from the system. I've tried sending mail using "mail", but it never gets anywhere and mailq reports "No route to host".

If Evolution can send mail, it seems like a command line app like mail should be able to do it too if I can just get it configured correctly including telling it which smtp mail server to use.

Thanks for any help.

Perpetual Newbie, 8^)
Mike Jewell
 
Old 08-22-2005, 12:19 PM   #2
zzyzx
LQ Newbie
 
Registered: Feb 2005
Distribution: Slackware 10.1
Posts: 20

Rep: Reputation: 0
I'm pretty new myself, so you may want to double check this, but try putting this in your /home/<user>/.mailrc or /root/.mailrc file.

set smtp=<smtp server, eg: mail.adelphia.net>
set from=<your email addy>

I use slackware, but this should let "mail" from the command line send through your ISP's mail server.

zzyzx
 
Old 08-22-2005, 02:18 PM   #3
Utah
Member
 
Registered: Apr 2004
Distribution: Fedora Core 3
Posts: 73

Original Poster
Rep: Reputation: 15
Thanks for the reply zzyzx. I tried that but it didn't do the trick.

Here's my .mailrc file (modified names for security):

set smtp=mail.myisp.net
set from=me@myaddress.com

When I look at the output of mailq (sendmail -bp), I see this:

-----Q-ID----- -- Size-- -----Q-Time----- ------------ Sender/Recipient-----------
j7MIg3T3028243 7 Mon Aug 22 11:42 <mikej@localhost.localdomain>
(Deferred: mail.somewhere.com.: No route to host)
<somebody@somewhere.com>

Note, sendmail thinks the "Sender" is "mikej@localhost.localdomain", NOT what I set in the .mailrc file.

So, is mail even reading that file?


When Evolution sends mail, does it use sendmail at all or does it use some other method? It seems to me (in my relative network ignorance) that to simply send a text email, one would not even need a mail server running. Wouldn't you just send the packets out on the internet using SMTP to your SMTP server and that would be it. (Any and all education is welcome) 8^)

Mike
 
Old 08-22-2005, 02:32 PM   #4
zzyzx
LQ Newbie
 
Registered: Feb 2005
Distribution: Slackware 10.1
Posts: 20

Rep: Reputation: 0
Are you typing "sendmail... " from the commandline?

When I use the commandline I type: mail -s "subject" <recipient email>. The mail command is actually the nail program which uses the mailrc config file.

You are correct in that you do not need sendmail running in order to send out mail.
 
Old 08-22-2005, 07:04 PM   #5
Utah
Member
 
Registered: Apr 2004
Distribution: Fedora Core 3
Posts: 73

Original Poster
Rep: Reputation: 15
No, I'm not typing the sendmail command. I only refered to it since it seems to be running and trying to do something with the mails I send using "mail".
I'm simply typing:

$ mail somebody@somewhere.com (I use an actual address.)

"mail" then prompts for subject, then lets me enter lines of text ending in a dot by itself on a line. Then a prompt for Cc: and it finished.

I'm trying to simplify it all down to basics to try to get a handle on what's going on:

I stop sendmail.

I send mail to myself using:
$ mail mylogname
...

I type: mail
No mail for mylogname

I restart sendmail

I type: mail
Now I see the mail I just sent to myself.

It appears that "mail" needs "sendmail" to work. But where did the mail I sent get stored while sendmail was stopped? It was not in /var/spool/mail/mylogname. But it was obviously put somewhere since sendmail found it as soon as I restarted it.

So, can "mail" really be used to send mail (even to myself) without a mail server running?

"Somewhat confused by mail",
Mike 8^)
 
Old 08-22-2005, 11:24 PM   #6
zzyzx
LQ Newbie
 
Registered: Feb 2005
Distribution: Slackware 10.1
Posts: 20

Rep: Reputation: 0
I think you've reached the end of my "expertise". A few other places to look

- when you type "man mail" is the man page for nail? mail can be an alias for several different mail programs. I tried commenting out those same lines from my .mailrc file and my mail command stopped working, so that's obviously a piece of the puzzle for nail. If you aren't using nail maybe your mail program uses a different user config file. Setting those smtp and from variables in the proper file may do the job.

- does your /var/log/maillog list any errors? You are using FC3 so that might be way off since I'm running Slackware.

Hopefully, another config file is the easy answer. Let me know how it goes.

zzyzx
 
Old 08-24-2005, 07:44 PM   #7
Utah
Member
 
Registered: Apr 2004
Distribution: Fedora Core 3
Posts: 73

Original Poster
Rep: Reputation: 15
I double checked and no, I'm definately not using nail. (I might look into it though) And the man pages for mail clearly show that ~/.mailrc is the user's config file for the app. Everything I read makes me think that the mail program, by itself, is not capable of sending mail over the internet using SMTP. (I'm probably wrong.) It seems to need a mail server running like sendmail so I'm guessing I just don't have sendmail setup correctly. But I don't even see anything in the sendmail man pages about defining an external SMTP server.

Anyway, I know that in *IX, there are almost always many ways to skin any particular cat. So I did some googling and found:

1) SMTP is REALLY SIMPLE! You can send email from a terminal with just a few simple commands. That's why it's called "SIMPLE Mail Transfer Protocol" 8^)

2) To do it from a program is harder since the protocol requires waiting for the replies from the SMTP server for sending the next command, etc. A "here" document in a shell script doesn't work because it doesn't wait for replies.

3) There is a really slick little Perl script that simply does just what I want. It's called "sendEmail" (http://caspian.dotconf.net/menu/Software/SendEmail/) and it works great. Don't even need to compile, etc since it's just a stand-alone script (as long as you have the Perl interpreter on your machine). It just does the proper connecting, talking, waiting, talking, etc in the SMPT language to fire off your mail without the overhead of a mail server, etc, etc. Cool!


I'd still love to know how to do this with "mail", "sendmail", etc. but for now, I'm back in business.

Thanks for your pointers, etc.

Utah

Mike Jewell
One-Up Audio
 
  


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
Simple SMTP Mail Sending? usulsuspct Linux - Software 3 01-27-2005 03:11 PM
Sending output to mail account through cron. gian2oo1 Slackware 2 01-18-2005 12:54 PM
sending smtp mail the-chains Linux - General 0 12-08-2004 07:44 PM
Cron sending mail to root bspicer Linux - General 2 05-01-2002 12:52 PM
Who is Cron and why is he sending me all this mail?... lhoff Linux - Newbie 3 03-06-2002 04:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:15 AM.

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