Page 1 of 1

[SOLVED] Swift SMTP Authentication problem

Posted: Thu May 03, 2007 8:05 pm
by jackbravo
Hi

I'm using latest Swift (3.1.5) and I have a problem with SMTP Authentication.
My server does require smtp authentication, but swift is giving me:

Code: Select all

Authentication is not supported by the server but a username and password was given.
If I set up the smtp with Evolution it works (if I disable authentication in Evolution I can't send mail).
But in swift it throws me that Exception.

Code: Select all

$smtp = new Swift_Connection_SMTP($host, $port, $secure);
        //$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
        $smtp->setUsername($user);
        $smtp->setPassword($pass);
        $swift = new Swift($smtp);
From Evolution I know that the server uses Login AUTH. But either way (setting the authenticator or not) it fails.
Thanks.

Posted: Fri May 04, 2007 5:12 am
by Chris Corbyn
I'm changing this behaviour in forthcoming versions. I'm guessing you use a server which doesn't declare what types of authentication it supports... either that, or worse, it doesn't declare that it supports ESMTP.

I'm planning to just override whatever the server says anyway if the user requests to authenticate... you will get errors if the server doesn't like it though ;)

Posted: Fri May 04, 2007 8:44 am
by jackbravo
I guess I can live with that ;-) hehehe.

When do you think this new version will be ready?

Or what do you think about downloading the source from SVN?
Do you use tags on SVN? Is the trunk usually stable or pretty edgy =P?

Thanks!

Posted: Fri May 04, 2007 2:18 pm
by Chris Corbyn
jackbravo wrote:I guess I can live with that ;-) hehehe.

When do you think this new version will be ready?

Or what do you think about downloading the source from SVN?
Do you use tags on SVN? Is the trunk usually stable or pretty edgy =P?

Thanks!
trunk is stable actually (I work for a commercial project which uses Swift from the trunk directly via svn:externals), but those changes haven't been implemented yet. I can work on them over the next few days whilst we have a long weekend :) I'd like to have v3.2 out soon anyway which will include some new features, the main one of which (enhanced fail-safe batch mailing support) is already almost finished in svn.

The way the repository uses tags is pretty wasteful in some ways.... *every* single release gets tagged according to it's version number, even just revisions. It just makes it easy for me to quickly look up old code though when people contact me about bugs, or when I need to refer to older implementations. I don't think there's anything in branches currently; I don't really have a need for it because development is pretty focuses with just me writing it.

There is actually another thread here which addresses your probably in a hackaround fashion if you need something working right away... I'll see if I can dig it up :)

Posted: Fri May 04, 2007 3:05 pm
by jackbravo
I'll checkout swift from svn then :D

I'm also thinking on looking at the source code, I have located where the problem is, so maybe I can provide a patch.

As for the other hackish thread, Yep! any pointer would be usefull.
Thanks

Posted: Fri May 04, 2007 5:10 pm
by Chris Corbyn
jackbravo wrote:As for the other hackish thread, Yep! any pointer would be usefull.
Somewhere far down in the thread I post a class, and the original poster in the thread gave some insight too. I'll have the code modified in svn within the next couple of days too so that providing a username and password forces Swift to just go ahead and give it a go. I just need to finish a couple of other things off first :)

EDIT | of course it would help if I remembered the damn link :P

viewtopic.php?t=66692&highlight=authent ... +supported

Posted: Fri May 04, 2007 7:12 pm
by jackbravo
I implemented the solution found there:

Code: Select all

<?php

require_once "lib/Swift.php";
Swift_ClassLoader::load("Swift_Connection_SMTP");

//Make a custom plugin just to hack at the responses and commands
class SayESMTP extends Swift_Events_Listener {
  function responseReceived(&$e) {
    if ($e->getCode() == 220) {
      $e->setString("220 ESMTP whatever");
      $swift =& $e->getSwift();
      $swift->connection->setExtension("AUTH", array("LOGIN"));
    }
  }
}

$smtp =& new Swift_Connection_SMTP("server.tld");
$smtp->setUsername("user");
$smtp->setPassword("pass");

//Force swift to wait for us to load a plugin
$swift =& new Swift($smtp, null, SWIFT_NO_START);
$swift->attachPlugin(new SayESMTP(), "hack");

//Now connect
$swift->connect();

//and continue as usual

$swift->send( .... );
But didn't worked. I think the method responseReceived is not being executed because i wrote echos there and nothing appened. Also it keeps giving me a:

Code: Select all

Authentication is not supported by the server but a username and password was given.

Posted: Sat May 05, 2007 3:45 am
by Chris Corbyn
Is this PHP5?

Code: Select all

<?php 

require_once "lib/Swift.php"; 
Swift_ClassLoader::load("Swift_Connection_SMTP"); 

//Make a custom plugin just to hack at the responses and commands 
class SayESMTP implements Swift_Events_ResponseListener { 
  public function responseReceived(Swift_Events_ResponseEvent $e) { 
    if ($e->getCode() == 220) { 
      $e->setString("220 ESMTP whatever"); 
      $swift = $e->getSwift(); 
      $swift->connection->setExtension("AUTH", array("LOGIN")); 
    } 
  } 
} 

$smtp = new Swift_Connection_SMTP("server.tld"); 
$smtp->setUsername("user"); 
$smtp->setPassword("pass"); 

//Force swift to wait for us to load a plugin 
$swift = new Swift($smtp, null, Swift::NO_START); 
$swift->attachPlugin(new SayESMTP(), "hack"); 

//Now connect 
$swift->connect(); 

//and continue as usual 

$swift->send( .... );

Posted: Sat May 05, 2007 1:54 pm
by Chris Corbyn
If you're running from svn, you should be able to drop that hacked bit of code and just authenticate as you would usually do :)

Posted: Sun May 06, 2007 7:46 am
by Chris Corbyn
Changes available in 3.2.0, just released.

it works!

Posted: Mon May 07, 2007 6:28 pm
by jackbravo
d11wtq wrote:Changes available in 3.2.0, just released.
worked like a charm!
thank you very much.