Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
What does 'mailq' report? –  Joe H. Sep 2 '09 at 16:28
    
mailq displayed the sendmail queue, currently containing 7 messages. –  lanrat Sep 2 '09 at 22:24
    
I'm going to assume this means that it's not reporting an errors for the messages, like the other Joe showed in his much more detailed example. Which means there's one other possibility -- sendmail's not even trying to deliver the message. If sendmail had been working, and now it's not, the most common situation I've seen is that the load on the system's gotten high enough that sendmail skips its processing. –  Joe H. Sep 3 '09 at 13:37

4 Answers 4

First check the message in the queue and the error log (/var/log/mail.err) Then in order to force deletion, you can do (even though it's in case of it's really stuck )

rm -rf /var/spool/mqueue/*
share|improve this answer
2  
WARNING This will delete all mail in the queue. You might want to move that mail to a safe location instead of deleting it. –  Joe Sep 2 '09 at 16:43
    
var/log/mail.err is empty. –  lanrat Sep 2 '09 at 22:29
    
Yes it will purge the queue. So if it's empty, it means there is no error. Maybe sendmail is not right configured. Do you use a smtp gateweay (another smtp server that will handle your messages) or does sendmail send mails by itself ? –  Razique Sep 3 '09 at 7:09

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 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 mis-matches bee 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
share|improve this answer
    
Thanks, you can see the output of one of the queue files in my edit. I don't seem to see anything wrong with it. –  lanrat Sep 2 '09 at 22:31

Look at the lines that say Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com. They tell you that your server was able to resolve an MX record for gmail.com, but it couldn't connect to the remote server. What happens when you telnet to port 25 on that host from the mail server? You should see something like this (note that I typed "quit"):

crunch:/Users/gerald$ telnet alt4.gmail-smtp-in.l.google.com 25
Trying 72.14.221.114...
Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP d4si791296fga.25
quit
221 2.0.0 closing connection d4si791296fga.25
Connection closed by foreign host.

Do you have any firewall rules in place that would block outbound connections on port 25?

share|improve this answer
up vote 0 down vote accepted

I found the solution.

My ISP started blocking port 25 by default to stop spammers. A quick call to them opened the port back up and all mail started flowing.

Thank you Joe for your help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.