while sending mail through applet

Hi All,

I have a problem while using the following code in my applet

Here is the code i got the exception.

public void postMail( String smtpHost, String recipients[], String subject,

String message , String file, String from) throws MessagingException

{

boolean debug = false;

//Set the host smtp address

Properties props = new Properties();

props.put("mail.smtp.host", smtpHost);

props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();

Session session = Session.getDefaultInstance(props, auth);

session.setDebug(debug);

// create a message

Message msg = new MimeMessage(session);

// set the from and to address

InternetAddress addressFrom = new InternetAddress(from);

msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];

for (int i = 0; i < recipients.length; i++)

addressTo = new InternetAddress(recipients);

msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type

msg.setSubject(subject);

msg.setSentDate(new Date());

if(!file.equals(""))

{

BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message

messageBodyPart.setText(message);

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

// Part two is attachment

messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(file);

messageBodyPart.setDataHandler(new DataHandler(source));

messageBodyPart.setFileName((new File(file)).getName());

multipart.addBodyPart(messageBodyPart);

msg.setContent(multipart);

}

else msg.setContent(message, "text/plain");

Transport.send(msg);

}

->exception

Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: javax/mail/MessagingException

And -->

Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: javax/mail/Authenticator

--

i set the jar file mail.jar and activation.jar file in tomcat webserver

webapp/ myproj/lib

Can any one please help me?

Thanks,

Kiran

[2299 byte] By [p.v.k.ka] at [2007-11-27 3:03:32]
# 1

The JVM can't find JavaMail or the JavaBeans Activation Framework (JAF) on the classpath.

Assuming your applet is packaged in a JAR file, you'll need the "archive" attribute to specify not just your applet's JAR file but also the JavaMail and JAF JARs too, so all 3 get downloaded to the browser.

<applet archive="your.jar,mail.jar,activation.jar" ... />

Alternatively you can permanently install JavaMail and JAF on the client machine (PATH_TO_JRE/lib/ext folder).

However, the default applet security policy won't allow connections to machines other than the one from which the applet was downloaded. You will have to change the policy on the client to allow SMTP connections. (To put it another way, if you do get the JavaMail/JAF classes sent to the browser, you'll get SecurityExceptions.)

A better (?) way of doing this would be to have a servlet that the applet can make requests to, and have the server send the mail.

RichFearna at 2007-7-12 3:47:14 > top of Java-index,Desktop,Core GUI APIs...