I am using javax.mail API(1.2), bundled with the j2ee package, for an automated email generation of user registration,and getting the following exception
The full stack trace is java.security.AccessControlContext.checkPermission(AccessControlContext.java :264) java.security.AccessController.checkPermission(AccessController.java:427) java.lang.SecurityManager.checkPermission(SecurityManager.java:532) java.lang.Se curityManager.checkWrite(SecurityManager.java:962) java.io.File.mkdir(File.java: 1119) java.io.File.mkdirs(File.java:1148) org.apache.catalina.loader.WebappClass Loader.findResourceInternal(WebappClassLoader.java:1811) org.apache.catalina.loa der.WebappClassLoader.findResource(WebappClassLoader.java:920) org.apache.catali na.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1138) jav a.lang.Class.getResourceAsStream(Class.java:1998) javax.mail.Session.loadProvide rs(Session.java:793) javax.mail.Session.(Session.java:81) javax.mail.Session.get Instance(Session.java:103) website.Email.sendThanksToUser(Email.java:37) blah bl ah blah
My site is designed using jsp It uses a shared server instance (tomcat 5.0.27) All other smtp configurations are fine, I 've tested them on my local server. Some body Pls Help
We can always tell you what a particular Exception means, better yet you can always check it on the Java/J2EE API (javadoc) online. Hence just pasting a stacktrace and noting that those are the exceptions you get is not really helpful to either us or you. What would be helpful is a code snippet of where your exception is thrown.
i.e. it gets thrown or caught after trying which block.
Believe me we don't want to see your exact code but simple explanations or even pseudo-code would go a long way. e.g:
try{
// here I try to create a Message
// as well as invoke the send method
// from a class in JavaMail- (keep in
// mind I've never gone through the
// JavaMail API so this is simply an
// educated guess of what the pseudo
// would look like)
}catch(AServerException se){
System.out.println("Connection failed - or send failed");
// Once again AServerException is a fictitions
// class that handles one form of an exception.
se.printStackTrace();
}catch(SendFailedExcpetion fe){
System.out.println("Send Failed");
fe.printStackTrace();
}
Something like this would be useful, I'm not saying you'd get an answer, but you'd definitely have a better shot at getting one. Most of us have been around Java for years so even if we are not familiar with a particular API e.g. JavaMail, we just might be able to point you in the right direction.
Session.getInstance(Properties, Authenticator);
// see JavaMail API
[/null]
No clearly if you pass in null when it is expecting
a properly set Authenticatory object, it will
definitely be throwing those Security Exceptions.
Try setting up a proper javax.mail.Authenticator and
pass it in accordingly. E.g:
[java]
my_session = Session.getInstance(yourProperty, new Authenticator(){
// override the abstract methods or simply
// pass this one in by creating a class extension
});
Session mailSession = Session.getInstance(props, new MailAuthenticator());
class MailAuthenticator extends Authenticator { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("myid", "mypwd"); } }
Here's a little debugging trick. You know that your code crashes on creation of Mail Session see where it crashes (most likely when you instantiate MailAuthenticator) Stick in some print statements.
System.out.println("Creating Mail Session");
Session mailSession = Session.getInstance(props, newnew MailAuthenticator());
System.out.println("created mail Session");
class MailAuthenticator extends Authenticator
{
public PasswordAuthentication
getPasswordAuthentication() {
System.out.println("Password Authentication");
returnnew PasswordAuthentication("myid", "mypwd");
}
}
[/java