props.put("mail.smtp.sasl.enable", "false");
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
SMTPTransport transport = new SMTPTransport(session, unusedUrlName);
// If the password is non-null, SMTP tries to do AUTH LOGIN.
final String emptyPassword = null;
transport.connect(host, port, userEmail, emptyPassword);
/*
* I couldn't get the SASL infrastructure to work with JavaMail 1.4.3;
* I don't think it was ready yet in that release. So we'll construct the
* AUTH command manually.
*/
XoauthSaslResponseBuilder builder = new XoauthSaslResponseBuilder();
byte[] saslResponse = builder.buildResponse(userEmail,
XoauthProtocol.SMTP,
oauthToken,
oauthTokenSecret,
consumer);
saslResponse = BASE64EncoderStream.encode(saslResponse);
transport.issueCommand("AUTH XOAUTH " + new String(saslResponse),
235);
return transport;
}