SMTP Connection From (localhost) Closed By QUIT

MichaelEC

Member
Jan 30, 2019
6
0
1
Ireland
cPanel Access Level
Website Owner
Hi,

I've been having some issues sending out automated emails through G-Mails SMTP settings. I have been back and forward with Google for quite some time now and they are very adamant that the setup is correct on their end (2-Step Auth, Less Secure Apps etc) along with my PHP file being setup correctly too (see screenshot, password removed and email changed).

Attached to this thread is my PHP File setup along with errors from the exim_mainlog that show the connection being refused by localhost.

PHP Setup:

[removed - please attach images directly to the thread]

exim_mainlog error (email changed & IP replaced with [xx.xx.xx.xx]:xxxxx):

Code:
2019-01-30 13:58:40 SMTP connection from [xx.xx.xx.xx]:xxxxx (TCP/IP connection count = 1)
2019-01-30 13:58:42 dovecot_login authenticator failed for (localhost) [xx.xx.xx.xx]:xxxxx: 535 Incorrect authentication data ([email protected])
2019-01-30 13:58:42 SMTP connection from (localhost) [xx.xx.xx.xx]:xxxxx closed by QUIT
2019-01-30 13:58:42 SMTP connection from [127.0.0.1]:xxxxx (TCP/IP connection count = 1)
2019-01-30 13:58:42 SMTP connection from (localhost) [127.0.0.1]:xxxxx closed by QUIT
I'm completely stumped on what to do next - I've tried a lot of different methods as instructed by Google's Support but to no avail.

This is the specific error message I get when running the PHP file in my browser;

authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]
I know the credentials I'm using are a proper email address (not an alias), it is under G-Suite and the password is the correct App Password.

Something the Google Support member said which stands out was
"I can tell for sure what what I see that you need to allow the server on your end/local host to make the authentication using the credentials of the added settings and not the one of the Cpanel or account added on the local host."
If anyone has any idea on what to do next, that'd be great - please don't hesitate to ask me for more information.
 
Last edited by a moderator:

GOT

Get Proactive!
PartnerNOC
Apr 8, 2003
1,772
326
363
Chesapeake, VA
cPanel Access Level
DataCenter Provider
Your logs indicate you are trying to connect to localhost as its the localhost reporting the authentication failure.

Are you running CSF? What is the setting for smtp_redirect set to if so?
 
  • Like
Reactions: MichaelEC

MichaelEC

Member
Jan 30, 2019
6
0
1
Ireland
cPanel Access Level
Website Owner
Your logs indicate you are trying to connect to localhost as its the localhost reporting the authentication failure.

Are you running CSF? What is the setting for smtp_redirect set to if so?
Hi Got,

We aren't running CSF as far as I can see (Under the Plugins section on WHM right?)
 

MichaelEC

Member
Jan 30, 2019
6
0
1
Ireland
cPanel Access Level
Website Owner
Just bumping this for more options!

I'd assume something needs to be configured to stop trying to connect to localhost when running the PHP Mail script? Here's my PHP Script using Gmail SMTP;

PHP:
$host = "smtp.gmail.com";
$username = "[email protected]";
$password = "redacted";
$port = "587";
$to = "[email protected]";
$email_from = "[email protected]";
$email_subject = "Email To All People" ;
$email_body = "Something Something Something" ;
$email_address = "[email protected]";

$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
};
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hi @MichaelEC

It looks like you're using local credentials for the mail
you should be using your full gmail address or google apps address. If you're using the latter you need to ensure that the domain is put into
Code:
/etc/remotedomains
and removed from
Code:
/etc/localdomains
as it appears it's trying to authenticate with [email protected] locally.
 
  • Like
Reactions: MichaelEC

MichaelEC

Member
Jan 30, 2019
6
0
1
Ireland
cPanel Access Level
Website Owner
Hi Lauren,

Thanks for the response.

[email protected] is actually just a placeholder, I'm using a Google Suite address which is [email protected]

I've just had a look at localdomains and its only got two lines in it called server.company.io & XXXX.XXXX001.local

In remotedomains there's also only one line called company.io

(company is a placeholder for company name & XXXX replaces a string of characters)

Not sure what I must do here!
 
Last edited:

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hi @MichaelEC

The question is about the domain you're using google apps with. If that domain is hosted on the server you need to add it to /etc/remotedomains or the server will continue to attempt to authenticate it locally which will continue to fail.
 

MichaelEC

Member
Jan 30, 2019
6
0
1
Ireland
cPanel Access Level
Website Owner
Hi @MichaelEC

The question is about the domain you're using google apps with. If that domain is hosted on the server you need to add it to /etc/remotedomains or the server will continue to attempt to authenticate it locally which will continue to fail.
Hi @cPanelLauren,

I get you, thanks.

Unfortunately our domain is already in /etc/remotedomains - it's the only line in the file.
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hi @MichaelEC


Good that it's in remote domains just to be sure it's not also listed in localdomains correct? Without being able to see the configuration it's really hard to tell what's going wrong with the authentication. If you'd like to, please open a ticket using the link in my signature? Once open please reply with the Ticket ID here so that we can update this thread with the resolution once the ticket is resolved.


Thanks!
 

MichaelEC

Member
Jan 30, 2019
6
0
1
Ireland
cPanel Access Level
Website Owner
Hi @cPanelLauren

It is also listed in localdomains.

I have an open ticket now, the number is 11333509.

There are some suggestions from that ticket for me to try so I'll get those actioned sometime tomorrow or Friday, hopefully one of them works!
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hi @MichaelEC


You also most likely need to remove it from /etc/localdomains or it's going to continue to attempt to authenticate locally. I'll check in on the ticket as well.

Thanks!
 

poliet

Registered
Dec 9, 2020
3
0
1
Barcelona
cPanel Access Level
Website Owner
I had the same error. For reference and others, here are the steps how I resolved it:

1. Need to allow less secure apps in your google admin (https://admin.google.com/ac/security/lsa)
2. Create an app specific password in your gmail (https://myaccount.google.com/u/5/apppasswords) to bypass Google security concerns and 2-factor auth issues. You must use the newly created app specific password instead of your regular login gmail $password.
3. Try to send mail, which is likely to be blocked by a Captcha. Clear the captcha (https://accounts.google.com/DisplayUnlockCaptcha) and wait 5-10 min.
4. This should work now. If some mails get through but you still get an occassional Authentication Error 535 throw, it's better to setup routing in gmail -> Google Admin -> Goodle Workspace -> Gmail -> Routing (last option). This changes your smtp from smpt.gmail.com to smtp-relay.gmail.com.
4b. If you code supports, make sure that you pass your domain with your EHLO. Google occasionally complaints that localhost won't cut it with some auth settings. (SMTP relay: Route outgoing non-Gmail messages through Google - Google Workspace Admin Help).