[Twisted-Python] about smtp client auth problem.

Jean-Paul Calderone exarkun at divmod.com
Tue Apr 15 08:01:13 EDT 2008


On Tue, 15 Apr 2008 18:38:28 +0800, Chris <chris.yan at saybot.com> wrote:
>Hi,
>I am trying to use twisted to implement a script to send the email,I got
>some problem.here is the script:
>####################
> [snip]
>
><<< 250-AUTH
><<< 250-AUTH=PLAIN LOGIN LOGIN
><<< 250-XXXXXXXA
><<< 250 XXXB
>
> [snip]
>
>some guy said,this script force to use the LOGIN auth,because something
>wrong with the server,is it true?I don't know very much about the mail
>server,does any one can tell me if I can make my twisted script work?I
>really like to implement a twisted one.

Indeed, the ESMTP server is not correctly advertising its support for the
AUTH extension.  

You can hack around this by going up to the ESMTP protocol implementation
in Twisted and tweaking its behavior a bit with a subclass (untested):

  from twisted.mail.smtp import ESMTPClient

  class ForceLOGINESMTPClient(ESMTPClient):
      def authenticate(self, code, resp, items):
          if 'AUTH=PLAIN' in items:
              items['AUTH'] = 'PLAIN ' + items['AUTH=PLAIN']
          return ESMTPClient.authenticate(self, code, resp, items)

Then, use this protocol with your ESMTPSenderFactory.  The idea here is
that this subclass notices the particular kind of malformed response this
server sends and adjusts it slightly.  This is a bit better than the other
version you gave which just hard-coded LOGIN, since it should manage to
actually correctly interpret the mechanisms the server is advertising.  Of
course, it may be a bit more fragile too, since it depends on the exact
kind of misformatting the server is doing.  If you want to avoid that,
you can hard-code LOGIN by just setting items['AUTH'] = 'LOGIN'.

Hope this helps,

Jean-Paul




More information about the Twisted-Python mailing list