Monday, May 10, 2010

Evil Net::SMTP Hack with SMTP Authentication

For some reason my hosting provider doesn't like Perl's Net::SMTP SMTP authentication of PLAIN. Everytime, it gives an error.

Unfortunately, there is not way to tell Net::SMTP::auth method to only use a predefined mechanism from Authen::SASL. It will tries the first one every time.... This happens to be the ever failing PLAIN not the working LOGIN flavor.

I tried to pass in a Authen::SASL to the auth method but it will just be smart and override the mechanism list :(

Well, here is my evil to turn the mechanism method into a read only method, put in the top of my script:

package Authen::SASL;
no warnings 'redefine'; # suppress sub refine warning
sub mechanism { return 'LOGIN'; }
package main;

Awful hack but right now I can't find a better way around this problem without completely overriding the the auth method, which seems much worse.

now to figure out how to open a good bug for Net::SMTP.