LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to send automatic emails to user (https://www.linuxquestions.org/questions/linux-software-2/how-to-send-automatic-emails-to-user-569276/)

GATTACA 07-14-2007 08:27 AM

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.

marozsas 07-14-2007 09:15 AM

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


GATTACA 07-14-2007 10:44 AM

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?

cojo 07-14-2007 11:49 PM

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

service sendmail start

GATTACA 07-15-2007 09:09 AM

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?

marozsas 07-16-2007 05:49 AM

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,

cojo 07-16-2007 10:34 PM

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.


All times are GMT -5. The time now is 02:50 AM.