Discussion:
[Classpathx-javamail] GNU JavaMail CRAM-MD5 Support
Jos Collin-ERS,HCLTech
2010-10-05 03:37:34 UTC
Permalink
Hello,

I'm using GNU JavaMail in my program. I'm using a PLAIN SMTP Authentication right now. But my SMTP server is configured to use CRAM-MD5. So I want to know whether GNU JavaMail supports CRAM-MD5 authentication for SMTP.

Please help.

Thanks,
Jos Collin
DISCLAIMER:
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------
Chris Burdess
2010-10-05 07:47:10 UTC
Permalink
Jos Collin-ERS,HCLTech wrote:
> I'm using GNU JavaMail in my program. I'm using a PLAIN SMTP Authentication right now. But my SMTP server is configured to use CRAM-MD5. So I want to know whether GNU JavaMail supports CRAM-MD5 authentication for SMTP.

Yes it does.

If for some reason it keeps falling back to PLAIN, it may be that the server is presenting the authentication mechanisms in the "wrong" order. You can override the order in which authentication mechanisms are attempted by the client by setting the mail.smtp.auth.mechanisms session property (e.g. "mail.smtp.auth.mechanisms=CRAM-MD5,PLAIN,LOGIN"), see the SMTP provider package JavaDoc for more information.
--
Chris Burdess
Jos Collin-ERS,HCLTech
2010-10-05 08:01:05 UTC
Permalink
Thanks Chris for the information.

So you mean, I have to set the property mail.smtp.auth.mechanisms as props.put("mail.smtp.auth.mechanisms", "CRAM-MD5"). 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?

Thanks,
Jos Collin
-----------------------


//Create a Properties object and set the properties
Properties props = 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");
props.put("mail.smtp.ssl.enable", "true");

//Authenticator can be used only by creating a child class
Authenticator auth = new SMTPAuthenticator();

// Create a session using the authenticator object
Session mailSession = Session.getDefaultInstance(props, auth);

Transport transport = mailSession.getTransport();

________________________________________
From: Chris Burdess [***@bluezoo.org]
Sent: Tuesday, October 05, 2010 1:17 PM
To: classpathx-***@gnu.org
Cc: Jos Collin-ERS,HCLTech
Subject: Re: [Classpathx-javamail] GNU JavaMail CRAM-MD5 Support

Jos Collin-ERS,HCLTech wrote:
> I'm using GNU JavaMail in my program. I'm using a PLAIN SMTP Authentication right now. But my SMTP server is configured to use CRAM-MD5. So I want to know whether GNU JavaMail supports CRAM-MD5 authentication for SMTP.

Yes it does.

If for some reason it keeps falling back to PLAIN, it may be that the server is presenting the authentication mechanisms in the "wrong" order. You can override the order in which authentication mechanisms are attempted by the client by setting the mail.smtp.auth.mechanisms session property (e.g. "mail.smtp.auth.mechanisms=CRAM-MD5,PLAIN,LOGIN"), see the SMTP provider package JavaDoc for more information.
--
Chris Burdess


DISCLAIMER:
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------
Chris Burdess
2010-10-05 08:39:47 UTC
Permalink
Jos Collin-ERS,HCLTech wrote:
> Thanks Chris for the information.
>
> 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?
>
> Thanks,
> Jos Collin
> -----------------------
>
>
> //Create a Properties object and set the properties
> Properties props = 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");

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

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

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

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

--
Chris Burdess
Jos Collin-ERS,HCLTech
2010-10-05 08:53:13 UTC
Permalink
> final String userName = ...;
> final String password = ...;
> Authenticator auth = new Authenticator() {
> protected PasswordAuthentication getPasswordAuthentication() {
> return new PasswordAuthentication(userName, password);
> }
> };

Yes, I have already done that in my code. So I will do the following and test the code and see whether it authenticate with the SMTP server using CRAM-MD5.

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

Thanks for your support,
Jos Collin
________________________________________
From: Chris Burdess [***@bluezoo.org]
Sent: Tuesday, October 05, 2010 2:09 PM
To: Jos Collin-ERS,HCLTech
Cc: classpathx-***@gnu.org
Subject: Re: [Classpathx-javamail] GNU JavaMail CRAM-MD5 Support

Jos Collin-ERS,HCLTech wrote:
> Thanks Chris for the information.
>
> 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?
>
> Thanks,
> Jos Collin
> -----------------------
>
>
> //Create a Properties object and set the properties
> Properties props = 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");

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

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

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

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

--
Chris Burdess
Jos Collin-ERS,HCLTech
2010-10-05 07:46:44 UTC
Permalink
Hello,

I'm using GNU JavaMail in my program, which is a BugReporting Tool. I'm using a PLAIN SMTP Authentication in my code, right now. But my SMTP server is configured to use CRAM-MD5. So I want to know whether GNU JavaMail supports CRAM-MD5 authentication for SMTP.

Please help.

Thanks,
Jos Collin

--
Please ignore the Disclaimer note, as I'm not doing it.
Loading...