Sendmail queues mail, doesn’t send

sendmail

I have an Ubuntu server with php and sendmail.

When I use PHP to send an email via sendmail the mail just sits in the sendmail queue forever and never gets sent. Even if I force flush it it still sits in the queue.

What could the cause of this be and how can I fix it?

Thanks.

EDIT:
The output of "cat /var/spool/mqueue/qfn82FuSu3009905" is:

V8
T1251906988
K1251927546
N6
P570369
I8/1/121795
MDeferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Fwbs
$_localhost [127.0.0.1]
$rESMTP
$sworld0.com
${daemon_flags}
${if_addr}127.0.0.1
S<www-data@world0.com>
A<>
MDeferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
rRFC822; user@gmail.com
RPFD:<user@gmail.com>
H?P?Return-Path: <g>
H??Received: from world0.com (localhost [127.0.0.1])
    by world0.com (8.14.3/8.14.3/Debian-6) with ESMTP id n82FuSu3009905
    for <user@gmail.com>; Wed, 2 Sep 2009 08:56:28 -0700
H?x?Full-Name: www-data
H??Received: (from www-data@localhost)
    by world0.com (8.14.3/8.14.3/Submit) id n82FuR5T009904;
    Wed, 2 Sep 2009 08:56:27 -0700
H??Date: Wed, 2 Sep 2009 08:56:27 -0700
H??Message-Id: <200909021556.n82FuR5T009904@world0.com>
H??To: user@gmail.com
H??Subject: Website feedback form
H??MIME=Version: 1.0
H??Content-type: text/html; charset=iso-8859-1
H??From: dude@domain.com
.

I do not see where anything is going wrong.

EDIT 2:

Well, I can ping the server but not talk to it over telnet, how could that be?
I have no firewall running.

root@world0:~# telnet alt4.gmail-smtp-in.l.google.com 25
Trying 72.14.221.114...
telnet: Unable to connect to remote host: Connection timed out
root@world0:~# ping 72.14.221.114
PING 72.14.221.114 (72.14.221.114) 56(84) bytes of data.
64 bytes from 72.14.221.114: icmp_seq=1 ttl=241 time=167 ms
64 bytes from 72.14.221.114: icmp_seq=2 ttl=241 time=171 ms
64 bytes from 72.14.221.114: icmp_seq=3 ttl=241 time=169 ms
64 bytes from 72.14.221.114: icmp_seq=4 ttl=241 time=222 ms
^C
--- 72.14.221.114 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3015ms
rtt min/avg/max/mdev = 167.840/182.722/222.589/23.055 ms

Best Answer

To find out more about the disposition of a message, try this:

mailq

You'll see lots of lines like this:

n812uLGQ001861 12089700 Mon Aug 31 19:56 <******@*****.org>
                 (Deferred: Connection timed out with c.mx.mail.yahoo.com.)
                                         <******@yahoo.com>
n82FR6a3019167 22388400 Wed Sep  2 08:27 <******@*****.net>
                 (reply: read error from g.mx.mail.yahoo.com.)
                                         <******@yahoo.com>

where n82FR6a3019167 is the message ID

ls -al /var/spool/mqueue/*<message ID>

Try looking at those files (they're just text files), particularly the one named qn82FR6a3019167 (or whatever your message ID number is. Note: the 'q' before the message ID. You should be able to determine the status of the message, which will hopefully help determine what isn't working properly.

cat /var/spool/mqueue/qn82FR6a3019167

If that doesn't help, you may need to look at the smart relay setting in sendmail.cf. Your PHP server might need to relay mail out through a Smart Relay host.


Next, I would try a manual SMTP session from your PHP server to the Google mail server.

telnet alt4.gmail-smtp-in.l.google.com 25

Trying 209.85.129.114...
Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP p9si790839fkb.7

helo <yourhostname>
250 mx.google.com at your service

mail from:<youremail@youraddress.com>
250 2.1.0 OK p9si740839fkb.7

rcpt to:<whoever@gmail.com>
250 2.1.5 OK p9si740839fkb.7

data
354  Go ahead h2si759562fkh.29
Subject: This is a test

Testing!
.
250 2.0.0 OK 1251933071 h2si759562fkh.29
quit

221 2.0.0 closing connection h2si759562fkh.29

Connection closed by foreign host.

This will hopefully tell you if your IP address is being blocked, or if some SPF (Sender Policy Framework) problem exists, or if you have DNS name mismatches that may be causing your email to be denied or deferred.

I presume you truncated the listing of the details in your reply. Your system really should have a valid hostname with reverse DNS entries for that hostname.

Also, check your /etc/hosts file to ensure that your IP address is listed correctly there. It's pretty common to have hostname mismatches be a problem when relaying email to the internet (at least, in my experience).

Something like:

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1        localhost.localdomain localhost
xxx.xxx.xxx.xxx  yourhostname.yourdomain.com yourhostname
Related Topic