Depending on the Servlet engine, you may have to edit a properties
file that sets the CLASSPATH for servlets. It may not be the same
as the environment variable.

Also, you have to have the Activation Framework (JAF 1.0) jar file
in the servlets' classpath as well.

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Aurelio
Sent: Thursday, May 13, 1999 5:33 AM
To: [EMAIL PROTECTED]
Subject: SENDING E-MAIL FROM A A SERVLET


Hello,

    I am trying to send e-mail from a servlet using JavaMail API. The
operation is very simple... but doesn't work.
The code below works fine used in a application, but when used in a
servlet, always fails. Moreover, it seems to "lock" the servlet, because
I always obtain "Document contains no data", although I send to the
browser flags since the first lines of the servlet. All these flags are
correctly sent when I comment this method, but when I uncomment it,
fails and I can't see even the flags that are sent before the calling to
the method.

The code is:

 public void sendMail(String msg) {

     Properties props = new Properties();
     props.put("mail.smtp.host", "servername");

     javax.mail.Session sesion =
javax.mail.Session.getDefaultInstance(props, null);

     try {

     Message msg = new MimeMessage(sesion);
     msg.setFrom(new InternetAddress("sender"));

     InternetAddress[] addr = {new InternetAddress("receiver")};
     msg.setRecipients(Message.RecipientType.TO, addr);

     msg.setSubject("Subject");
     msg.setSentDate(new java.util.Date());

     msg.setText(msg);

     Transport.send(msg);

     } catch (MessagingException e) {
   //...
     }
  }

It works fine from an application. Maybe some problem with the classpath
of the servlet engine?
JavaMail API is correctly installed, and in the classpath.

Any help is apperciated.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to