Fun With SMTP
Sunday, March 13, 2005, at 05:20PM
By Eric Richardson
I'll warn you ahead of time, this post's geeky.
Before I head out east tomorrow morning, I wanted to get email working on my phone. Like Sean I don't plan to recieve email on the phone, but I do want to be able to use it for sending photos. The s710a actually has pretty much the same email configuration any normal email client would have, so most of the settings were easy enough to configure. But authenticated SMTP (sending mail) was failing, and I needed to figure out why...
Luckily, I run an SMTP server -- qpsmtpd -- that's written in Perl and easy to tweak. In a strange small-world twist, qpsmtpd was actually written by Ask Bjørn Hansen who lives in LA and writes a blog.
In any case, I first downloaded and installed the auth_imap plugin for qpsmtpd. I got that working sending mail from a local email client, but it was failing sending from my phone. I got into lib/Qpsmtpd/Auth.pm and started debugging. I ended up discovering that an extra return character was getting stuck onto the password getting sent from the phone. I changed:
$passClear = <>;
$passClear = decode_base64($passClear);
To this:
$passClear = <>;
$passClear =~ s![\n\r]!!g;
$passClear = decode_base64($passClear);
And all was suddenly well.
Well, not really. Now I discovered that the auth_imap plugin wasn't trying to log me in. Instead of auth_imap just registering:
$self->register_hook( "auth-plain", "authimap" );
It needed to register:
$self->register_hook( "auth-plain", "authimap" );
$self->register_hook( "auth-login", "authimap" );
That changed, mail finally worked. Now I can send and receive email on my phone via IMAP and authenticated SMTP. I'm reasonably happy with myself.