LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 07-14-2007, 08:27 AM   #1
GATTACA
Member
 
Registered: Feb 2002
Location: USA
Distribution: Fedora, CENTOS
Posts: 209

Rep: Reputation: 32
How to send automatic emails to user


Hello.

I'm trying to send an automatic email to system users when there jobs are done on a queue. I've used sendmail but the program sends the messages to /var/spool/mail/<user> and not the user's real email address: user@somewhereelse.com.

Since I only want simple outbound emailing I don't think I need a full-blown email-server (perhaps I'm wrong). Is there a simple way to send email to users?

The system I'm using is CentOS 5.0 32bit.

All advice is appreciated.

Thanks.
 
Old 07-14-2007, 09:15 AM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
use the mail program...
Code:
echo "You have a job X done" | mail -s "your job at queue X is done" user@somewhereelse.com
or even a multiline body message
Code:
mail -s "your job at queue X is done" user@somewhereelse.com <<EOM
Put your message here in theses lines.
You can use any shell variables too. 
Your PATH is $PATH

regards,
EOM
 
Old 07-14-2007, 10:44 AM   #3
GATTACA
Member
 
Registered: Feb 2002
Location: USA
Distribution: Fedora, CENTOS
Posts: 209

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by marozsas
use the mail program...
Code:
echo "You have a job X done" | mail -s "your job at queue X is done" user@somewhereelse.com
Thanks!

I tried this with the mail -v option to get verbose info.

This is what I got to the screen:
Code:
user@somewhere.com... Connecting to [127.0.0.1] via relay...
user@somewhere.com... Deferred: Connection refused by [127.0.0.1]
This tells me that something about my system is misconfigured, I'd guess I need to tell it the mail server to use?.

Any suggestions on what's wrong and how to fix it?
 
Old 07-14-2007, 11:49 PM   #4
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Rep: Reputation: 31
what is the status of sendmail? If it's stop, you need to start it with this

service sendmail start
 
Old 07-15-2007, 09:09 AM   #5
GATTACA
Member
 
Registered: Feb 2002
Location: USA
Distribution: Fedora, CENTOS
Posts: 209

Original Poster
Rep: Reputation: 32
You were right cojo, Sendmail service was off.
I started there service and tried again. This is what I got...

Code:
echo "Test email" | mail -v -s "ws email" user@somewhere.com
user@somewhere.com... Connecting to [127.0.0.1] via relay...
220 localhost.localdomain ESMTP Sendmail 8.14.1/8.14.1; Sun, 15 Jul 2007 09:58:10 -0400
>>> EHLO localhost.localdomain
250-localhost.localdomain Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From:<user@localhost.localdomain> SIZE=52 AUTH=user@localhost.localdomain
250 2.1.0 <user@localhost.localdomain>... Sender ok
>>> RCPT To:<user@somewhere.com>
>>> DATA
250 2.1.5 <user@somewhere.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 l6FDwAdx021369 Message accepted for delivery
user@somewhere.com... Sent (l6FDwAdx021369 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 localhost.localdomain closing connection
I don't it's configured correctly since it's connecting to localhost. Can someone point me in the right direction to configure this?
 
Old 07-16-2007, 05:49 AM   #6
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
In fact, it is correct. The normal behaviour is to connect to the localhost to delivery e-mail generated locally.
The localhost can be configured to send e-mails directly or to connect to a relay host to send e-mails.

In my setup here at work, I have this working in this way. The several servers can send e-mails directly and only the mailserver can accept incoming e-mails. It is up to you.

I can't help you with sendmail, because I use postfix for years.
In postfix there is a configuration file named transport where I set for what domains I can send e-mails directly or for what domains I need to relay e-mails.

I hope this can help,
 
Old 07-16-2007, 10:34 PM   #7
cojo
Member
 
Registered: Feb 2003
Location: St. Louis
Distribution: RedHat 8
Posts: 262

Rep: Reputation: 31
You don't need to do anything at all. Just make sure your sendmail is enable and started. It's working right now. As long your company mail server will except mail from your Fedora box.
 
  


Reply



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
Sendmail doesn't send emails Bodyweb Linux - Software 5 07-18-2006 08:53 AM
sendmail doesn't send emails outside dev_mohamed Linux - Networking 2 08-28-2005 03:42 PM
Automatic saving of emails by time and subject captainpotato Linux - Software 0 04-05-2005 02:21 AM
send 50-100 emails? codec Linux - Software 1 11-23-2004 07:28 AM
Can't send or Receive Emails amohime Linux - Networking 4 04-11-2003 02:42 AM

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

All times are GMT -5. The time now is 04:19 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