BillFogarty
asked on
Sending an email from a java application
However i am still having problems...
I am running on Windows XP, i have copied the "mail.jar" and the "activation.jar" files into the folder
C:\WINDOWS\java\classes directory, i downloaded them. I got them from the JavaMail API 1.2 release and the JAVABEANS ACTIVATION FRAMEWORK respectively.
I then added the classpath to them in my Visual J++. I specified the paths as:
C:\WINDOWS\java\classes\ma il.jar
C:\WINDOWS\java\classes\ac tivation.j ar
but i get an Exception in thread "main" java.lang.NoClassDefFoundE rror: javax/mail/Message
I am really struggling to realise what i have done wrong...
can anyone spot any error?
Or does anyone have any code for sending an email. I have been trying all day, if you have a class that would work, aswell as the method call or constructor to the class...if so i will award you with the pints
I am running on Windows XP, i have copied the "mail.jar" and the "activation.jar" files into the folder
C:\WINDOWS\java\classes directory, i downloaded them. I got them from the JavaMail API 1.2 release and the JAVABEANS ACTIVATION FRAMEWORK respectively.
I then added the classpath to them in my Visual J++. I specified the paths as:
C:\WINDOWS\java\classes\ma
C:\WINDOWS\java\classes\ac
but i get an Exception in thread "main" java.lang.NoClassDefFoundE
I am really struggling to realise what i have done wrong...
can anyone spot any error?
Or does anyone have any code for sending an email. I have been trying all day, if you have a class that would work, aswell as the method call or constructor to the class...if so i will award you with the pints
ASKER
ya i have the mail.jar and activation.jar in both directories....
have you tried compiling/running from command line.
objects touched on this, but I believe that you'll want to be sure that jar files are in lib, not classes.
-corey
-corey
> that jar files are in lib
They need to be in lib/ext, not lib.
They need to be in lib/ext, not lib.
Ah, true.
Add rt.jar (C:\Program Files\JavaSoft\JRE\1.3.1\l ib\rt.jar) to the J++ classpath(also mail.jar and activation.jar from ext directory), and change the interpreter into the Options tab to be java.exe ( for example C:\jdk1.3.1\bin\java.exe). This would works!
Hi
You have to put the jars (mail.jar & activation.jar) into the following directory
JAVA_HOME\jre\lib\ext\
Also following is the code to send email
You have to import the following
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
/**Make Sure you are defining the variables correctly*/
/**Source Code*/
public static String sendMail() {
Properties properties = new Properties();
properties.put("mail.smtp. host", "<your smtp host>");
properties.put("mail.from" , "Sun Microystems");
Session session = Session.getInstance(proper ties,null) ;
try {
Message message = new MimeMessage(session);
int i=0;
InternetAddress[] address = {new InternetAddress("<address here>")};
message.setRecipients(Mess age.Recipi entType.TO , address);
message.setFrom(new InternetAddress("fromaddre ss@here.co m"));
message.setSubject("Hi");
message.setContent(mail_Co ntent, "text/html");
transport = session.getTransport(addre ss[0]);
transport.connect();
transport.sendMessage(mess age,addres s);
}catch (Exception e) {
System.out.println("Except ion: " + e.toString());
return "Error sending Mail";
}
return "Mail Successfully Send!";
}
You have to put the jars (mail.jar & activation.jar) into the following directory
JAVA_HOME\jre\lib\ext\
Also following is the code to send email
You have to import the following
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
/**Make Sure you are defining the variables correctly*/
/**Source Code*/
public static String sendMail() {
Properties properties = new Properties();
properties.put("mail.smtp.
properties.put("mail.from"
Session session = Session.getInstance(proper
try {
Message message = new MimeMessage(session);
int i=0;
InternetAddress[] address = {new InternetAddress("<address here>")};
message.setRecipients(Mess
message.setFrom(new InternetAddress("fromaddre
message.setSubject("Hi");
message.setContent(mail_Co
transport = session.getTransport(addre
transport.connect();
transport.sendMessage(mess
}catch (Exception e) {
System.out.println("Except
return "Error sending Mail";
}
return "Mail Successfully Send!";
}
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts removed
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venci75
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts removed
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Venci75
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In genberal though you should simply be able to put the jar files into your 'ext' directory(s) and they'll get picked up automatically.
Your ext directory(s) (you may have two one for jdk, and one for jre) will be in the JDK/JRE folder inside the lib folder.