File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes java mail and Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "java mail and Tomcat" Watch "java mail and Tomcat" New topic
Author

java mail and Tomcat

James Fraley
Greenhorn

Joined: Feb 28, 2012
Posts: 4
I'm resurrecting a project I started some while ago. My first challenge is to recreate the environment I was using. I'm mostly there, but I can't get mail to send. I have installed Tomcat 7.0.27 and it seems to work. It servers JSPs and Servlets and can access my database server. But, I can't get mail to send. I know the code works, because it did work when I last used it.

- I'm running java 1.6.0_32
- I downloaded both javamail1_4_5.zip and jaf-1_1_1.zip to my WEB-INF\lib directory
- I copied javamail1_4_5.zip to javamail1_4_5.jar and jaf-1_1_1.zip to jaf-1_1_1.jar in my WEB-INF\lib directory (so both the .jar and .zip files are in my WEB-INF\lib directory)
- I added both javamail1_4_5.jar and jaf-1_1_1.jar to my classpath
- Finally, I copied javamail1_4_5.jar to mail.jar and jaf.jar to jaf.jar in my WEB-INF\lib.

None of the above seems to be the solution.

So, how do I configure the java environment properly to send email???
-------------------------------------------------------------------------------------------
The errors I get are:org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 19 in the generated java file
Only a type can be imported. javax.mail.AuthenticationFailedException resolves to a package

An error occurred at line: 20 in the generated java file
Only a type can be imported. javax.mail.Authenticator resolves to a package

An error occurred at line: 21 in the generated java file
Only a type can be imported. javax.mail.PasswordAuthentication resolves to a package

An error occurred at line: 22 in the generated java file
Only a type can be imported. javax.mail.Message resolves to a package

An error occurred at line: 23 in the generated java file
Only a type can be imported. javax.mail.MessagingException resolves to a package

An error occurred at line: 24 in the generated java file
Only a type can be imported. javax.mail.Session resolves to a package

An error occurred at line: 25 in the generated java file
Only a type can be imported. javax.mail.Transport resolves to a package

An error occurred at line: 26 in the generated java file
Only a type can be imported. javax.mail.internet.AddressException resolves to a package

An error occurred at line: 27 in the generated java file
Only a type can be imported. javax.mail.internet.InternetAddress resolves to a package

An error occurred at line: 28 in the generated java file
Only a type can be imported. javax.mail.internet.MimeMessage resolves to a package
-------------------------------------------------------------------------------------------------------
The code generating the errors (out of the .java file) are:

import javax.mail.AuthenticationFailedException;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

Thanks
Jim
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Tomcat doesn't do javamail. That's one of the things that makes it different from the full-stack J2EE servers. So yes, you do have to add jars to the webapp's WEB-INF/lib directory.

There are 2 primary jars required: javamail.jar and activation.jar. The activation jar is mandatory even though on the face of it, it's not specifically related to javamail.

Beyond that, there's a possibility that some of the mail API has changed since then, but I don't know.


Customer surveys are for companies who didn't pay proper attention to begin with.
James Fraley
Greenhorn

Joined: Feb 28, 2012
Posts: 4
I resolved this issue today. The Under Java 1.6, jaf-1_1_1.zip isn't necessary. And, the zip file must be unzipped and the mail.jar copied to the lib directory. I'll try to post a more complete description later today. Thank you
 
 
subject: java mail and Tomcat