Re: GNU JavaMail CRAM-MD5 Support

Chris Burdess <[email protected]> Tue, 5 Oct 2010 09:39:47 +0100
Newsgroups gmane.comp.java.classpath.extensions.javamail
Message-ID <[email protected]>
Jos Collin-ERS,HCLTech wrote:
> Thanks Chris for the information.
>=20
> So you mean, I have to set the property mail.smtp.auth.mechanisms as =
props.put("mail.smtp.auth.mechanisms", "CRAM-MD5").

Yes.

> The following is my code where I set the properties. Also, do I have =
to do anything additional, as the CRAM-MD5 authentication is different =
from PLAIN? How does it receive the challenge from the server and send =
the digest back?
>=20
> Thanks,
> Jos Collin
> -----------------------
>=20
>=20
>    	//Create a Properties object and set the properties
>        Properties props =3D new Properties();
>        props.put("mail.transport.protocol", "smtp");
>        props.put("mail.smtp.host", SMTP_HOST_NAME);
>        props.put("mail.smtp.port", SMTP_HOST_PORT);
>        props.put("mail.smtp.auth", "true");=20

props.put("mail.smtp.auth.mechanisms", "CRAM-MD5");

>        props.put("mail.smtp.ssl.enable", "true");
>=20
>        //Authenticator can be used only by creating a child class
>        Authenticator auth =3D new SMTPAuthenticator();

final String userName =3D ...;
final String password =3D ...;
Authenticator auth =3D new Authenticator() {
	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(userName, password);
	}
};

>=20
>        // Create a session using the authenticator object
>        Session mailSession =3D Session.getDefaultInstance(props, =
auth);
>=20
>        Transport transport =3D mailSession.getTransport();

--=20
Chris Burdess