GMail Authentication - Strange

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

GMail Authentication - Strange

Post by VinceP »

Hi there,

Firstly, great work on Swift Mailer. Does exactly what I want and a lot faster than PHPMailer. Unfortunately, I'm running into a really bizarre issue with Gmail.

Occasionally it throws up errors like so:

Code: Select all

PHP Fatal error:  <br /><strong>Uncaught Error</strong> of type [swift_connectionexception] with message [Authentication failed using username 'me@gmail.com' and password '*******'<h3>Log Information</h3><pre>++ Log level changed to 4
++ Authentication mechanism 'LOGIN' attached.
++ Trying to connect...
++ Trying to connect to SMTP server at 'tls://smtp.gmail.com:465
<< 220 mx.google.com ESMTP n33sm14073506wag.47
>> EHLO localhost.localdomain
<< 250-mx.google.com at your service, [64.13.231.44]
250-SIZE 28311552
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES
++ SMTP extension 'SIZE' reported with attributes [28311552].
++ SMTP extension '8BITMIME' reported with attributes [].
++ SMTP extension 'AUTH' reported with attributes [LOGIN, PLAIN].
++ SMTP extension 'ENHANCEDSTATUSCODES' reported with attributes [].
++ Trying to authenticate with username 'me@gmail.com'.
++ Trying 'LOGIN' authentication...
>> AUTH LOGIN
<< 334 VXNlcm5hbWU6
>> cmVnaXN0cmF0aW in /var/www/vhosts/mydomain/httpdocs/inc/php/lib/Swift/Errors.php on line 99
Content-type: text/html
X-Powered-By: PHP/4.3.9
 
Here's my PHP code

Code: Select all

 
<?php
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 
// Set Logging:
$log =& Swift_LogContainer::getLog();
$log->setLogLevel(4);
 
// Create connection with authentication
$conn = new Swift_Connection_SMTP("smtp.gmail.com", 465, SWIFT_SMTP_ENC_TLS);
$conn->setUsername('me@gmail.com');
$conn->setPassword('mypassword');
$smtp =& new Swift($conn);
 
$message =& new Swift_Message("Test Subject", "Test Body";
 
if ($smtp->send($message, "someoneelse@gmail.com", "me@gmail.com")) {
// Succeeded:
$log =& Swift_LogContainer::getLog();
echo $log->dump(true);
}
else {
// Failed:
$log =& Swift_LogContainer::getLog();
echo $log->dump(true);
}
}
?>
 
Bizarrely, this happens completely randomly. I know my authentication is good, because I can manually login to Gmail using the same details. Any ideas? Is this likely just an issue with the Gmail SMTP servers?

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: GMail Authentication - Strange

Post by Chris Corbyn »

No response has come back from Gmail after sending the username. Sounds like a network issue. Hopefully you're not using gmail to send large volumes of mail since this could be the problem... it kicks you off after 100 mails in <insert unknown short space of time here>.
VinceP
Forum Newbie
Posts: 7
Joined: Tue Jan 22, 2008 9:18 pm

Re: GMail Authentication - Strange

Post by VinceP »

Hi Chris, thanks for the response.

I can't actually find any written limits on the number of mails sent using Gmail per day on their site, is there anything written there? I see there's a limit of 500 recipients per message, or 100 if using SMTP directly, but nothing about a max number of messages.
EDIT: Just for the record, the account I'm trying to test with has probably only sent about 20 e-mails today, to 1 individual at a time. Incidently if I change the account details to a brand new account, it occasionally happens too.

If I'm experiencing network issues, do you recommend I try and increase the timeouts or just loop through the function until it's successful?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: GMail Authentication - Strange

Post by Chris Corbyn »

The only reason I know Gmail have limits is because I've consistently had support requests about the gmail connection dropping after exactly 100 emails and then subsequent attempts failing. I don't have anything in writing, nor have I looked so there's a possibility I'm wrong ;) I suspect they'd have been getting fed up with people blasting emails through their servers without even using their email service very much (and hence not clicking on ads) :)

Increasing the timeout could help yes, although I think the default is 15 seconds anyway which is pretty long. It's difficult without seeing exactly what the problem is; right now all I can see for sure is that gmail asked for a username, Swift sent the username and Gmail didn't respond.
meti_alb
Forum Newbie
Posts: 12
Joined: Thu Jan 17, 2008 2:46 pm

Re: GMail Authentication - Strange

Post by meti_alb »

What abou the following code Chris?
What does it mean ? Any ideas?

Code: Select all

 
Fatal error: Uncaught exception 'Swift_BadResponseException' with message 'Expected response code(s) [250] but got response []' in /hsphere/local/home/albstream/maasbesa.org/admin/swiftmail/lib/Swift.php:250 Stack trace: #0 /hsphere/local/home/albstream/maasbesa.org/admin/swiftmail/lib/Swift.php(310): Swift->assertCorrectResponse(Object(Swift_Events_ResponseEvent), 250) #1 /hsphere/local/home/albstream/maasbesa.org/admin/swiftmail/lib/Swift.php(319): Swift->command('RSET', 250) #2 /hsphere/local/home/albstream/maasbesa.org/admin/swiftmail/lib/Swift.php(455): Swift->reset() #3 /hsphere/local/home/albstream/maasbesa.org/admin/actions.php(63): Swift->send(Object(Swift_Message), Object(Swift_RecipientList), Object(Swift_Address)) #4 {main} thrown in /hsphere/local/home/albstream/maasbesa.org/admin/swiftmail/lib/Swift.php on line 250 
 
would the Antiflood Plugin separate the BCC s on 98 each time in the following example using swift->send(), or does that work only with the batchSend() ?

Code: Select all

 
....
$swift->attachPlugin(new Swift_Plugin_AntiFlood(98, 5), "anti-flood");
....
$recipients = new Swift_RecipientList();
$recipients->addTo("newsletter@somedomain.org");
.....
.....
while($row = mysql_fetch_array($result))
{
    $recipients->addBcc($row['email']);
}
......
if($swift->send($mesazhi, $sender)) echo "success"; else echo "failure";
.....
 
 
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: GMail Authentication - Strange

Post by Chris Corbyn »

You know, sending them all as Bcc isn't faster than a batchSend(). Swift still has to modify the message for every recipient so that the Bcc header only has that recipient's name in it ;) It's just sendmail on unix systems which happens to be fast for Bcc since it reads the headers instead of accepting a list of recipients.

The anti-flood plugin probably isn't doing what you expect it to in this case since it works on a per-message basis. 100 recipients in one message is just one send to Swift. Thinking about it, I should probably distinguish between sending a full message and sending to one recipient as far as the events go. Something I'll look at in v4.

batchSend() would work as expected.
meti_alb
Forum Newbie
Posts: 12
Joined: Thu Jan 17, 2008 2:46 pm

Re: GMail Authentication - Strange

Post by meti_alb »

seems like I can't find a way around having my own newsletter.
my hosting smtp failed as well so I turned again to gmail but I guess, I was wrong when I was imagining the Bcc scenario same as when a human has to send it....I was thinking 100 bcc is one email, and then it's gmail's resopnsibility to take care of the rest.
hmmm.... :banghead:
Post Reply