phpmailer suddenly got very slow - phpmailer

I use phpmailer for sending emails and while it worked flawlesly until now, I noticed that sending emails got very very slow, around 2-3 minutes. The mails are sent, but the waiting time is killing me.
My code is:
protected function SendPHPMailerMail($from = null, $name = null, $subject = null, $message = null)
{
require_once ('phpmailer/PHPMailerAutoload.php');
if($from && $name && $subject && $message)
{
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // sets GMAIL as the SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = 'tls'; // sets the prefix to the servier
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = 'x#gmail.com'; // GMAIL username
$mail->Password = 'pass'; // GMAIL password
$mail->AddReplyTo($from, $name);
$mail->AddAddress('x#gmail.com', 'Me');
$mail->SetFrom('x#gmail.com', 'Me');
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Send();
}
}
I tried debugging, there are no errors. I read in a different question thread that using gethostbyname('smtp.gmail.com'); worked for some, but not for me. I haven't changed anything on the server and this popped out of nowhere. Not sure what to do.
Thanks!
edit: used SMTPdebug=2 and this is what I get
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: EHLO www.host.com
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [107.182.234.254]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO www.host.com
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [107.182.234.254]250- SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: Y29udGFjdEBmaWxlY2x1c3Rlci5jb20=
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: Z2l6bW8uMTIzcXdl
SERVER -> CLIENT: 235 2.7.0 Accepted
CLIENT -> SERVER: MAIL FROM:<x#gmail.com>
SERVER -> CLIENT: 250 2.1.0 OK 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: RCPT TO:<x#gmail.com>
SERVER -> CLIENT: 250 2.1.5 OK 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Go ahead 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: Date: Thu, 20 Oct 2016 20:44:01 +0000
CLIENT -> SERVER: To: Me <x#gmail.com>
CLIENT -> SERVER: From: Me <x#gmail.com>
CLIENT -> SERVER: Reply-To: X <sender#gmail.com>
CLIENT -> SERVER: Subject: Partnership and business development
CLIENT -> SERVER: Message-ID: <6dae364927ad751cc524f07a77f5eea1#www.host.com>
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: text/plain; charset=iso-8859-1
CLIENT -> SERVER:
CLIENT -> SERVER: message
CLIENT -> SERVER:
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 2.0.0 OK 1476996370 90sm16517084otw.3 - gsmtp
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection 90sm16517084otw.3 - gsmtp
I replaced the actual values of the site and emails.

Related

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated in linux

Hi i want send a mail from my linux server my code block/project is working in my local(windows) but i get this error when i run my project in linux.
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
Here is my code block where is my problem? thanks.
string domain = "my.local";
string userName = "info";
string userPass = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("AkXyz2*"));
string host = "mail.mymail.com.tr";
string fromMail = "mymail#mymail.com.tr";
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
var smtp = new SmtpClient(host, 587);//port
smtp.EnableSsl = true;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(userName, userPass, domain);
smtp.Credentials = credentials;
smtp.ServicePoint.Expect100Continue = false;
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
...
...
smtp.Send(mail);

PHPMailer XOAUTH2 with gMail - SMTP Could not authenticate

I'm stuck with the following bizarre situation.
Trying to use phpMailer with gMail and xoauth2, and while the connection succeeds, just after sending the "request AUTH" command, I get back a response of "SMTP Error: Could not authenticate".
Using phpmailer 5.2.21, with oauth2 league 1.4.1 (all loaded via composer)
PHP Version: 7.0.1 (openssl is loaded)
The configuration is the following
$mailer = new PHPMailer();
$mailer->isSMTP();
$mailer->Host = 'smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->AuthType = 'XOAUTH2';
$mailer->oauthUserEmail = $userEmail;
$mailer->oauthClientId = $clientId;
$mailer->oauthClientSecret = $clientSecret;
$mailer->oauthRefreshToken = $token;
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer->setFrom($email);
$mailer->addAddress($recipient);
$mailer->Subject = $subject;
$mailer->Body = $message;
if (! $mailer->send())
throw new RuntimeException('Mail submission failed! ' . $mailer->ErrorInfo);
And the debug output is the following:
2017-01-05 08:14:47 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
2017-01-05 08:14:47 Connection: opened
2017-01-05 08:14:47 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP e7sm325303lfb.10 - gsmtp
2017-01-05 08:14:47 CLIENT -> SERVER: EHLO domain.tld
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
2017-01-05 08:14:47 CLIENT -> SERVER: STARTTLS
2017-01-05 08:14:47 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-01-05 08:14:47 CLIENT -> SERVER: EHLO domain.tld
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
2017-01-05 08:14:47 Auth method requested: XOAUTH2
2017-01-05 08:14:47 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
2017-01-05 08:14:47 SMTP Error: Could not authenticate.
2017-01-05 08:14:47 CLIENT -> SERVER: QUIT
The google app is authorized to use gmail (https://mail.google.com) and the whole process of setting up the app and getting the refresh token is successful. Moreover, I've gone over the whole phpmailer troubleshooting guide with no luck.
I'm probably missing something obvious here, but any ideas?
Thanks in advance
Yep, something simple - wrong class:
$mail = new PHPMailerOAuth;
Look at the gmail_xoauth.phps example provided with PHPMailer. Note that OAuth support will be substantially improved in PHPMailer 6.0.

PHPMailer cannot send via smtp.gmail.com

I'm trying to send mail with PHPMailer plugin via smtp.gmail.com. The sending works fine on my local computer but when I use my remote server with following code it delays the sending, normally around 30 seconds.
function sendAuthEmail($subject, $mail_body, $mailTo, $mailToTitle, $mailFrom, $fromTitle)
{
require 'PhpMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = 'no-reply#domail.com';
$mail->Password = 'password';
$mail->AddReplyTo($mailFrom, $fromTitle);
$mail->SetFrom($mail->Username, 'Domain.com');
$mail->AddAddress($mailTo, $mailToTitle);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->MsgHTML($mail_body);
if($mail->Send()) {
return;
} else {
die('There was an error: '.$mail->ErrorInfo.'</i>');
}
}
But when I try to use gethostbyname('smtp.gmail.com') it fails with following debug information:
2016-11-23 12:36:11 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP a47sm16079918qtc.17 - gsmtp
2016-11-23 12:36:11 CLIENT -> SERVER: EHLO www.sellercloud.com
2016-11-23 12:36:11 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [199.189.62.92] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2016-11-23 12:36:11 CLIENT -> SERVER: STARTTLS
2016-11-23 12:36:11 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2016-11-23 12:36:11 SMTP Error: Could not connect to SMTP host.
2016-11-23 12:36:11 CLIENT -> SERVER: QUIT
2016-11-23 12:36:11 SERVER -> CLIENT:
2016-11-23 12:36:11 SMTP ERROR: QUIT command failed:
2016-11-23 12:36:11 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
The problem with the server turned out to be a DNS resolving issue. PHP mailer couldn't resolve smtp.gmail.com correctly, and this was the main reason why none of the known fixes worked.
If you're having similar issue, check your DNS servers.

Mail rejected using phpmailer on GoDaddy.com host

Using this:
require("lib/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Username = "XXX#validGoDaddyAccount.com";
$mail->Password = "xxx";
$mail->Subject = $subject;
$mail->Body= $message;
$mail->AddAddress($toAddr);
$mail->FromName = "XXXXXXXXXXXX";
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtpout.secureserver.net";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
$mail->IsHTML(true);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
return true;
}
I get this response:
SMTP -> FROM SERVER:220 p3plsmtpa07-05.prod.phx3.secureserver.net ESMTP
SMTP -> FROM SERVER: 250-p3plsmtpa07-05.prod.phx3.secureserver.net hello [00.00.0.0], secureserver.net 250-HELP 250-AUTH LOGIN PLAIN 250-SIZE 31457280 250-PIPELINING 250-8BITMIME 250 OK
SMTP -> FROM SERVER:550 User XXX has exceeded their send quota
SMTP -> ERROR: MAIL not accepted from server: 550 User XXX has exceeded their send quota
The following From address failed: XXX : MAIL not accepted from server,550,User XXXm has exceeded their send quota
SMTP server error: User XXX has exceeded their send quota
Mailer Error: The following From address failed: XXX : MAIL not accepted from server,550,User XXX has exceeded their send quota
SMTP server error: User XXX has exceeded their send quota
I know about setting the SMTP Relays for GoDaddy accounts and they are set right. I can send email from this account all day long as long as I don't use PHPmailer.
see the following line
SMTP -> FROM SERVER:550 User XXX has exceeded their send quota
That's why it is rejecting.
The solution is that I needed to pre-authorize with POP prior to starting the SMTP operation:
require("lib/class.phpmailer.php");
require_once('lib/class.pop3.php');
$pop = new POP3();
$pop->Authorise('pop.server.net', 110, 30, 'username', 'password', 1);
$mail = new PHPMailer();
...

NodeJS SimpleSMTP server NOT make authentification

I try to use NodeJS SimpleSMTP. Get source from GIT (NodeJS SimpleSMTP)
And try add auth into smtp. My code is:
var SMTP_PORT = 2000;
var smtp = simplesmtp.createServer({debug:true, enableAuthentication:true});
smtp.listen(SMTP_PORT, function(err) {
if (err) console.log(err);
});
smtp.on("authorizeUser", function(connection, username, password, callback){
callback(null, true );
});
smtp.on("startData", function(connection){
console.log("Message from:", connection.from);
console.log("Message to:", connection.to);
});
smtp.on("data", function(connection, chunk){
});
smtp.on("dataReady", function(connection, callback){
console.log("Incoming message saved to /tmp/message.txt");
callback(null, "ABC1"); // ABC1 is the queue id to be advertised to the client
});
And for test I write simple client on Python:
smtpObj = smtplib.SMTP('localhost',2000)
smtpObj.set_debuglevel(1)
smtpObj.login('aaa', 'bbb')
sender="sender#email.com"
toemail = "recv#email.com"
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subj"
msg['From'] = sender
msg['To'] = "recv.email.com"
msg.attach(MIMEText("Hello world!",'html'))
smtpObj.sendmail(sender, [toemail], msg.as_string())
If I comment smtpObj.login('aaa', 'bbb') everything is OK, but I need auth user before send email. For auth in Simple SMTP I should use event authorizeUser and option enableAuthentication:true.
What I do wrong? Why server is not make authentification.
My logs:
Python with show debug info:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-mypc at your service, [127.0.0.1]\r\n'
reply: '250-8BITMIME\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250 STARTTLS\r\n'
reply: retcode (250); Msg: mypc at your service, [127.0.0.1]
8BITMIME
ENHANCEDSTATUSCODES
STARTTLS
Traceback (most recent call last):
File "/home/atlete/work/python/smtptest/src/test.py", line 6, in <module>
server.login("aaa", "bbb")
File "/usr/lib/python2.7/smtplib.py", line 576, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.
NodeJS debug info:
CONNECTION FROM 127.0.0.1
Connection from 127.0.0.1
OUT: "220 mypc ESMTP node.js simplesmtp"
COMMAND: ehlo [127.0.1.1]
OUT: "250-mypc at your service, [127.0.0.1]
250-8BITMIME
250-ENHANCEDSTATUSCODES
250 STARTTLS"
Connection closed to 127.0.0.1
Tough to say without seeing the SMTP logs (set simplesmtp debug:true), but you might check that the python auth method, i.e. LOGIN, matches what you set in the simplesmtp options.

Resources