This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
libgcj.security + classpath.security warning
- From: Øyvind Harboe <oyvind dot harboe at zylin dot com>
- To: java at gcc dot gnu dot org
- Date: Thu, 15 Jan 2004 17:40:04 +0100
- Subject: libgcj.security + classpath.security warning
- Organization: Zylin AS
I'm refining my unicodesmtp mail program(one of the examples in Mohans
latest wingcc) to support SMTP authentication, and I've encountered one or
two bumps on the road.
What does the warning below mean?
--
DEBUG: getProvider(): javax.mail.Provider[TRANSPORT,smtp,gnu.mail.providers.smtp
.SMTPTransport,nferrier@tapsellferrier.co.uk]
smtp: < 220 ice Microsoft ESMTP MAIL Service, Version: 6.0.2600.1106 ready at T
hu, 15 Jan 2004 16:18:50 +0100
smtp: > EHLO ice
smtp: < 250-ice Hello [10.0.0.11]
smtp: < 250-AUTH=LOGIN
smtp: < 250-AUTH LOGIN
smtp: < 250-SIZE 2097152
smtp: < 250-PIPELINING
smtp: < 250-DSN
smtp: < 250-ENHANCEDSTATUSCODES
smtp: < 250-8bitmime
smtp: < 250-BINARYMIME
smtp: < 250-CHUNKING
smtp: < 250-VRFY
smtp: < 250 OK
WARNING: could not properly read security provider files:
file:///datal/gcc/build/wingcc/lib/security/libgcj.security
file:///datal/gcc/build/wingcc/lib/security/classpath.security
Falling back to standard GNU security provider
Sent email to SMTP server
--
Below is a copy of a post I made to inetlib-discuss@gnu.org. The inetlib-discuss mailing
archive appears to be inoperational at the moment, hence the repeat below.
(http://mail.gnu.org/pipermail/classpath-inetlib/)
Subject: Null pointer exception in gnu.inet.smtp.SMTPConnection.authenticate
I'm having trouble with SMTP authentication.
- My application (below) works with Sun's javamail-1.3.1
- The method call below returns null, which causes an exception that is
eventually converted to a an AuthenticationException.
SaslClient sasl = Sasl.createSaslClient(m, null, "smtp",
socket.getInetAddress().
getHostName(), p, ch);
- As near as I can tell from the documentation, null is a valid return
value from createSaslClient() and hence it is surprising that
authenticate() does not handle the case.
- If I uncomment authLogin() and plonk it into authenticate(), my app
works fine.
Ãyvind
import java.net.UnknownHostException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Send
{
/**
* not a pretty function call definition, but it isn't supposed to be.
* A "thin" interface between email sending capabilities and the C++
caller.
*/
public static int send(String smtp,
final String login,
final String pw,
String from,
String[] to,
String[] bcc,
String subject,
String body)
{
int ok=1; //generic error
try
{
/** Set up session props and session. */
Properties sessionProps = System.getProperties();
sessionProps.put("mail.smtp.host", smtp);
if (login.length()>0||pw.length()>0)
{
sessionProps.put("mail.smtp.auth", "true");
}
Session m_session = Session.getDefaultInstance(sessionProps);
m_session.setDebug(true);
MimeMessage message = new MimeMessage(m_session);
message.setFrom(new InternetAddress(from));
for (int i=0; i<to.length; i++)
{
message.addRecipients(Message.RecipientType.TO, to[i]);
}
for (int i=0; i<bcc.length; i++)
{
message.addRecipients(Message.RecipientType.BCC, bcc[i]);
}
message.setSubject(subject, "UTF8");
message.setText(body, "UTF8");
Transport transport = m_session.getTransport("smtp");
transport.connect(smtp, login, pw);
try
{
transport.sendMessage(message, message.getAllRecipients());
}
finally
{
transport.close();
}
ok=0;
}
catch (AddressException e)
{
// I haven't seen this thrown.
ok=3;
}
catch (NoSuchProviderException e)
{
int x=0;
}
catch (javax.mail.AuthenticationFailedException e)
{
// bad username or password
ok=2;
}
catch (SendFailedException e)
{
// the server exists, but does not respond. anti-spam?
int x=0;
}
catch (MessagingException e)
{
Exception nested=e.getNextException();
if (nested!=null)
{
try
{
UnknownHostException host=(UnknownHostException)nested;
// there is no such host. Typo.
ok=4;
} catch (ClassCastException e2)
{
}
} else
{
// the server exists, but does not respond or fails. Antispam?
}
}
return 0;
}
}