cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Emails on the box

Henry Chua
Super Advisor

Sending Emails on the box

Hi Guys,

I have a problem, i am trying to write a cron job to send mail to some mail account when an alert is detected. I try sending mail out using command:

echo "testing"|mail -s test test@gmail.com

but it doesnt work. I guess it is being blocked. Is there anyway i can go around this?

Best regards
Henry
6 REPLIES
Ivan Ferreira
Honored Contributor

Re: Sending Emails on the box

For that to work, your MTA must be correctly configured. The configuration depends if you use sendmail or postfix.

Check the status of your messages using:

mailq -v

And post the results, that will give us a clue about what is going on.

Also, the last lines of the /var/log/maillog file.

Cheers.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Henry Chua
Super Advisor

Re: Sending Emails on the box

Hi Ivan,

Thanks for the response :) as per your request:

$ echo "test lalalala12345"|mail -s "testing" chua_ka@yahoo.com
$ mailq -v
/var/spool/clientmqueue (5 requests)
-----Q-ID----- --Size-- -Priority- ---Q-Time--- --------Sender/Recipient--------
l7K3UNiH023454 19 30059 Aug 20 11:30 henry
(Deferred: Connection refused by [127.0.0.1])
(---:chua_ka@yahoo.com---)
chua_ka@yahoo.com
(Deferred: Connection refused by [127.0.0.1])
l7K0TUDi021767 7065 307005 Aug 20 08:29 MAILER-DAEMON
(Deferred: Connection refused by [127.0.0.1])
(---:root---)
root
(Deferred: Connection refused by [127.0.0.1])
l7JK26kn018851 5651 755691+Aug 20 04:02 root
(Deferred: Connection refused by [127.0.0.1])
(---:root---)
root
(Deferred: Connection refused by [127.0.0.1])
l7J6TUDi011212 1461 1921400 Aug 19 14:29 MAILER-DAEMON
(Deferred: Connection refused by [127.0.0.1])
(---:henry---)
henry
(Deferred: Connection refused by [127.0.0.1])
l7J1Y5RD008511 19 2370059+Aug 19 09:34 henry
(Deferred: Connection refused by [127.0.0.1])
(---:chua_ka@yahoo.com---)
chua_ka@yahoo.com
(Deferred: Connection refused by [127.0.0.1])
Total requests: 5

$tail -50 /var/log/maillog
Aug 20 09:29:30 tenessee sm-msp-queue[22333]: l7J1Y5RD008511: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=23:55:25, xdelay=00:00:00, mailer=relay, pri=2190059, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 10:29:30 tenessee sm-msp-queue[22900]: l7K0TUDi021767: to=root, delay=02:00:00, xdelay=00:00:00, mailer=relay, pri=217005, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 10:29:30 tenessee sm-msp-queue[22900]: l7JK26kn018851: to=root, ctladdr=root (0/0), delay=06:27:24, xdelay=00:00:00, mailer=relay, pri=665691, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 10:29:30 tenessee sm-msp-queue[22900]: l7J6TUDi011212: to=henry, delay=20:00:00, xdelay=00:00:00, mailer=relay, pri=1831400, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 10:29:32 tenessee sm-msp-queue[22900]: l7J1Y5RD008511: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=1+00:55:27, xdelay=00:00:00, mailer=relay, pri=2280059, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 11:29:30 tenessee sm-msp-queue[23439]: l7K0TUDi021767: to=root, delay=03:00:00, xdelay=00:00:00, mailer=relay, pri=307005, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 11:29:30 tenessee sm-msp-queue[23439]: l7JK26kn018851: to=root, ctladdr=root (0/0), delay=07:27:24, xdelay=00:00:00, mailer=relay, pri=755691, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 11:29:30 tenessee sm-msp-queue[23439]: l7J6TUDi011212: to=henry, delay=21:00:00, xdelay=00:00:00, mailer=relay, pri=1921400, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 11:29:36 tenessee sm-msp-queue[23439]: l7J1Y5RD008511: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=1+01:55:31, xdelay=00:00:00, mailer=relay, pri=2370059, relay=[127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Aug 20 11:30:25 tenessee sendmail[23454]: l7K3UNiH023454: from=henry, size=59, class=0, nrcpts=1, msgid=<200708200330.l7K3UNiH023454@mountuu.dnsalias.org>, relay=henry@localhost
Aug 20 11:30:25 tenessee sendmail[23454]: l7K3UNiH023454: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=00:00:02, xdelay=00:00:00, mailer=relay, pri=30059, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]

Please let me know if u need more info.

Thanks.
Henry
Steven Schweda
Honored Contributor

Re: Sending Emails on the box

> Connection refused [...]

This means that there's no program running to
receive e-mail. Or, in other words:

> For that to work, your MTA must be correctly configured.
Steven E. Protter
Exalted Contributor

Re: Sending Emails on the box

Shalom Henry,

Later releases of sendmail require that the sendmail daemon be running, even to accept local mail on localhost as is happening on your machine now.

Assuming no modification to default setup the procedure to get mail started is simple.

chkconfig sendmail on
# this sets up the daemon to run at startup.
service sendmail start


This is a Red Hat procedure.

The normal data center way of getting mail actually off the box involves using a mail relay server. What server this is is provided normally by your networking group.

In sendmail.cf you use DShostnamerelayserver

restart sendmail and your system will automaticallly relay using the relay server. That server must be explicitly configured to accept mail from your linux box or all the mail will be rejected.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Henry Chua
Super Advisor

Re: Sending Emails on the box

Hi all,

I have tried sending the mail after restarting the service. But the mail still was not able to reach the recipient

$echo "test lalalala12345"|mail -s "testing" chua_ka@yahoo.com

# mailq -v
/var/spool/mqueue is empty
Total requests: 0
[root@mountuu ~]#

maillog:
Aug 20 22:32:24 tenessee sendmail[30274]: l7KEWOmM030264: to=, delay=00:00:00, xdelay=00:00:00, mailer=l
ocal, pri=32259, dsn=2.0.0, stat=Sent
Aug 20 22:32:24 tenessee sendmail[30264]: l7KEWOmO030264: from=, size=361, class=0, nrcpts=1, msgid=<200
708190134.l7J1Y5RD008511@mountuu.dnsalias.org>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Aug 20 22:32:24 tenessee sm-msp-queue[30263]: l7J1Y5RD008511: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=1+12:58:19, xdela
y=00:00:00, mailer=relay, pri=3450059, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (l7KEWOmO030264 Message accepted for deli
very)
Aug 20 22:32:27 tenessee sendmail[30277]: l7KEWOmO030264: to=, ctladdr= (500/500), de
lay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120361, relay=b.mx.mail.yahoo.com. [66.196.97.250], dsn=2.0.0, stat=Sent (ok dirdel
)
Aug 20 22:32:32 tenessee sendmail[30269]: l7KEWOmG030264: to=, ctladdr= (500/500), de
lay=00:00:08, xdelay=00:00:08, mailer=esmtp, pri=120361, relay=e.mx.mail.yahoo.com. [216.39.53.1], dsn=2.0.0, stat=Sent (ok dirdel)
Aug 20 22:33:16 tenessee sendmail[30289]: l7KEXGN0030289: from=henry, size=59, class=0, nrcpts=1, msgid=<200708201433.l7KEXGN0030289
@mountuu.dnsalias.org>, relay=henry@localhost
Aug 20 22:33:20 tenessee sendmail[30293]: NOQUEUE: SYSERR(henry): can not chdir(/var/spool/mqueue/): Permission denied
Aug 20 22:33:21 tenessee sendmail[30290]: l7KEXGpR030290: from=, size=361, class=0, nrcpts=1, msgid=<200
708201433.l7KEXGN0030289@mountuu.dnsalias.org>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Aug 20 22:33:21 tenessee sendmail[30289]: l7KEXGN0030289: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=00:00:05, xdelay=00:0
0:05, mailer=relay, pri=30059, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (l7KEXGpR030290 Message accepted for delivery)
Aug 20 22:33:24 tenessee sendmail[30295]: l7KEXGpR030290: to=, ctladdr= (500/500), de
lay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120361, relay=c.mx.mail.yahoo.com. [216.39.53.3], dsn=2.0.0, stat=Sent (ok dirdel)
Aug 20 22:36:16 tenessee sendmail[30427]: l7KEaG0m030427: from=henry, size=59, class=0, nrcpts=1, msgid=<200708201436.l7KEaG0m030427
@mountuu.dnsalias.org>, relay=henry@localhost
Aug 20 22:36:16 tenessee sendmail[30428]: l7KEaGqT030428: from=, size=361, class=0, nrcpts=1, msgid=<200
708201436.l7KEaG0m030427@mountuu.dnsalias.org>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Aug 20 22:36:16 tenessee sendmail[30427]: l7KEaG0m030427: to=chua_ka@yahoo.com, ctladdr=henry (500/500), delay=00:00:00, xdelay=00:0
0:00, mailer=relay, pri=30059, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (l7KEaGqT030428 Message accepted for delivery)
Aug 20 22:36:19 tenessee sendmail[30430]: l7KEaGqT030428: to=, ctladdr= (500/500), de
lay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120361, relay=e.mx.mail.yahoo.com. [216.39.53.1], dsn=2.0.0, stat=Sent (ok dirdel)

Please let know if u have any ideas. Thanks.
Matt Shaffer_1
Regular Advisor

Re: Sending Emails on the box

I am also having this same issue with my rhel3u4 box. But it seems to only affect one user. She sends a mail and it queues up for random times (sometimes it's 4+ days, sometimes it's 9 minutes) before it even gets to sendmail. See the delay below. Also mqueue is empty.

Sep 10 20:30:30 3250 sm-msp-queue[20596]: l86Cqjgn003943: to=cjozwiak@wesco.com,
ctladdr=cheryl (3062/200), delay=4+11:37:45, xdelay=00:00:01, mailer=relay, pri
=297281, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (l8B0UTVG020835 Mes
sage accepted for delivery)

Thanks.
Matt