None of the previous answers actually said how to use PLAIN authentication, so I did some more digging. It turns out that authentication information is expected in base64. It's probably easiest to explain by example. Assume a username of "bob" and a password of "munchkin".
We'll first need to encode in base64. On a Linux-ish system, it goes likes this:
echo -en "\0bob\0munchkin" | base64
This incorporates the null characters as required, and also does the base64 encoding. We get this string out: AGJvYgBtdW5jaGtpbg==
.
Now, we can do the actual authentication (S
= Server, C
= Client):
S: * OK The Microsoft Exchange IMAP4 service is ready.
C: D0 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+
S: D0 OK CAPABILITY completed.
C: D1 AUTHENTICATE PLAIN
S: +
C: AGJvYgBtdW5jaGtpbg==
S: D1 OK AUTHENTICATE completed
And you're done!