简体   繁体   中英

Issues Sending Mail from Linux Server

I'm currently running Ubuntu 14.04.1. I've created a simple php script to use mail() to send a test email and then I access the script from Firefox. I have a VPS server with a single IP and no domain. Any time I trying sending an email, I receive errors from Google DNS blocking me. I've included the results of some files, which I believe are needed information.

The mail() that I used is mail("myemail@gmail.com", "test", "test"); . I've tried adding header information and more elaborate subject and body information, but that didn't help.

/var/log/mail.log

Dec 28 22:53:04 localhost sendmail[15365]: sBT3r4qG015365: from=www-data, size=83, class=0, nrcpts=1, msgid=<201412290353.sBT3r4qG015365@localhost.localdomain>, relay=www-data@localhost
Dec 28 22:53:05 localhost sm-mta[15366]: sBT3r4F1015366: from=<www-data@localhost.localdomain>, size=370, class=0, nrcpts=1, msgid=<201412290353.sBT3r4qG015365@localhost.localdomain>, proto=ESMTP, daemon=MTA-v4, relay=localhost.localdomain [127.0.0.1]
Dec 28 22:53:05 localhost sendmail[15365]: sBT3r4qG015365: to=myemail@gmail.com, ctladdr=www-data (33/33), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30083, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (sBT3r4F1015366 Message accepted for delivery)
Dec 28 22:53:05 localhost sm-mta[15368]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Dec 28 22:53:06 localhost sm-mta[15368]: sBT3r4F1015366: to=<myemail@gmail.com>, ctladdr=<www-data@localhost.localdomain> (33/33), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120370, relay=gmail-smtp-in.l.google.com. [IPv6:2607:f8b0:400e:c04::1b], dsn=5.0.0, stat=Service unavailable
Dec 28 22:53:06 localhost sm-mta[15368]: sBT3r4F1015366: sBT3r6F1015368: DSN: Service unavailable
Dec 28 22:53:06 localhost sm-mta[15368]: sBT3r6F1015368: to=<www-data@localhost.localdomain>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent
(email above has been changed to myemail@gmail.com)

/etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

/etc/hosts

ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

127.0.0.1 localhost.localdomain localhost servername
# Auto-generated hostname. Please do not remove this comment.
x.x.x.x servername
::1     localhost ip6-localhost ip6-loopback
127.0.0.2 servername
(servername and ip above have been changed to x.x.x.x and servername)

/var/spool/mail/www-data

I get about 70 lines after attempting to send one email, so I'll include what I think is most important. I get permanent fatal errors.

 550-5.7.1 
 Our system has detected that this
 message is likely unsolicited mail. To reduce the amount of spam sent
 to Gmail, this message has been blocked.

What I've tried:

I used to access the php script and it would take 30 seconds for the page to stop loading and I would receive the following errors in /var/log/mail.log :

 Dec 29 00:35:55 localhost sendmail[15632]: My unqualified host name (servername) unknown; sleeping for retry
 Dec 29 00:36:55 localhost sendmail[15632]: unable to qualify my own domain name (servername) -- using short name

To fix this, I changed the line 127.0.0.1 line in /etc/hosts to what it is now. Changing that line to any shorter version of what it is now results in receiving the error message above and the php script taking forever to load.

I also used to receive some other error message when sending mail. I looked up the issue and to fix it, I added the 127.0.0.2 line at the bottom. I can't seem to replicate the error message by removing that line anymore, so maybe that line is no longer serving a purpose.

I've tried looking into the DSN: Service unavailable in /var/log/mail.log , but all I found was changing the contents of /etc/hosts and /etc/hostname , which didn't help.

I've read a lot of articles about SPF records. This seems like it could be an contributing issue. The problem is every article mentions something about linking your domain to your IP. I don't have a domain, so I'm not sure if this really matters. They also talk about editing /var/named/data/ , but /var/named doesn't exist for me. I can confirm that if I try nslookup of my IP address on my windows machine, that I get the error Non-existent domain . This might also be related to the errors in /var/spool/mail/www-data .

I've looked into seeing if my IP is being blacklisted, but it doesn't seem to be. I recently received the IP and it's not a shared IP, so I don't think this is an issue. Ironically, at some point while trying to receive the emails, I did get 2 messages in my spam folder. I'm not even receiving them in spam anymore. Here is one of those emails:

Delivered-To: myemail@gmail.com
Received: by 10.112.202.37 with SMTP id kf5csp1654885lbc;
    Tue, 23 Dec 2014 20:55:39 -0800 (PST)
X-Received: by 10.68.200.68 with SMTP id jq4mr50110283pbc.30.1419396938944;
    Tue, 23 Dec 2014 20:55:38 -0800 (PST)
Return-Path: <www-data@servername>
Received: from servername ([x.x.x.x])
    by mx.google.com with ESMTPS id td7si16741093pab.130.2014.12.23.20.55.38
    for <myemail@gmail.com>
    (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
    Tue, 23 Dec 2014 20:55:38 -0800 (PST)
Received-SPF: temperror (google.com: error in processing during lookup of www-data@servername: DNS timeout) client-ip=x.x.x.x;
Authentication-Results: mx.google.com;
   spf=temperror (google.com: error in processing during lookup of www-data@servername:     DNS timeout) smtp.mail=www-data@servername
Received: from servername (localhost.localdomain [127.0.0.1])
by brauer (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id sBO4sYfV000877
for <myemail@gmail.com>; Tue, 23 Dec 2014 23:54:34 -0500
Received: (from www-data@localhost)
by servername (8.14.4/8.14.4/Submit) id sBO4sYgK000874;
Tue, 23 Dec 2014 23:54:34 -0500
Date: Tue, 23 Dec 2014 23:54:34 -0500
From: www-data <www-data@servername>
Message-Id: <201412240454.sBO4sYgK000874@servername>
To: myemail@gmail.com
Subject: test
X-PHP-Originating-Script: 0:file.php


test

Sorry if I included too much info. I'm just not sure what all is relevant. Any help would be appreciated. Thanks

I don't think you'll be successful at getting messages through to Gmail without SPF and/or DKIM, let alone without a domain. Why not just set up a domain, or use a separate SMTP server to send the mail? (eg, https://github.com/PHPMailer/PHPMailer ). Or use Mandrill, Amazon SES, SendGrid, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM