Can't send email. My java program used to be working running on server BUT does not work on servlet????????

I got a jave program used for sending email, it works running on server but NOT working on servlet.
I have done a JSP page which is invoked the email bean to send email

See my code below ( The Email is run on servlet)

package TEST;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;

public class Email
{
  public Email()
  {
  }
 
  public static int Send(String to
                        ,String from
                        ,String host
                        ,String emailSubject
                        ,String loginUser
                        ,String loginPwd
                        ,String msgText1
                        ,String msgText2
                        ,String AttachedFileName
                        ,String AttachmentName) throws Exception {

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

     emailSubject = emailSubject;
     Session session = Session.getDefaultInstance(props, null);
     //session.setDebug(debug);
     try {
       // create a message
       MimeMessage msg = new MimeMessage(session);
       InternetAddress[] address = {new InternetAddress(to)};
       msg.setFrom(new InternetAddress(from));
       msg.setRecipients(Message.RecipientType.TO, address);
       msg.setSubject(emailSubject);
       msg.setSentDate(new Date());
       msg.setText(msgText1);
       // Send email using SMTP
       Transport transport = session.getTransport("smtp");
       //transport.connect(host, loginUser, loginPwd);
       transport.connect("MAILSERVERHOST", "myEmailAccount", "myEmailPwd");
       Multipart mp = new MimeMultipart();
       if (msgText1 != null && !msgText1.equals("NULL")) {
            MimeBodyPart mbp = new MimeBodyPart();
            mbp.setText(msgText1);
            mbp.setHeader("Content-Type", "text/plain");
            mp.addBodyPart(mbp);
        }
        if (AttachedFileName != null && (!AttachedFileName.equalsIgnoreCase("NULL"))) {
            MimeBodyPart mbp = new MimeBodyPart();
            mbp.setHeader("Content-Type", "application/pdf");
            File attachments = new File(AttachedFileName);
            FileDataSource fileDataSource = new FileDataSource(attachments);
            mbp.setDataHandler(new DataHandler(fileDataSource));
            mbp.setFileName(AttachmentName);
            // mbp.setFileName(AttachedFileName);
            mp.addBodyPart(mbp);
            msg.setContent(mp);
        }

        msg.saveChanges();
        //msg.setContent(mp);
        transport.sendMessage(msg, msg.getAllRecipients());
        transport.close();
     }
     catch (AddressException ae) {
         System.out.println("address exception Error occured due to " + ae);
         ae.printStackTrace();
         Exception ex = null;
         if ((ex = ae.getNextException()) != null) {
             ex.printStackTrace();
         }
         return 1;
     }
     catch (Exception e)
     {
       System.out.println("Send:Exception due to " + e);
       e.printStackTrace();
       return 1;
     }
     return 0;
   } // Send

}


===================
My JSP invokes Email.send
==============


<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*, AAPL.*" errorPage="" %>
<P>

<%
    Email email = new Email();
    email.Send("Paul.smith@au.fujitsu.com"
              ,"Paul.smith@au.fujitsu.com"
              ,"SYD78CALIF"
              ,"My test"
              ,"SMITHP"
              ,"SPY"
              ,"Hope you are OK"
              ,""
              ,""
              ,"");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Employee Management</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="PRAGMA" value="NO-CACHE">
<DIV align="right">
  <img src="image/img_crm.jpg" width="360" height="70"/>
</DIV>
</P>The email has been send to YOU shortly
</head>


===================
Error messages

5/05/06 15:11:12 javax.mail.internet.ParseException
05/05/06 15:11:12       at javax.mail.internet.ParameterList.<init>(ParameterList.java)
05/05/06 15:11:12       at javax.mail.internet.ContentDisposition.<init>(ContentDisposition.java:70)
05/05/06 15:11:12       at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1040)
05/05/06 15:11:12       at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:790)
05/05/06 15:11:12       at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:216)
05/05/06 15:11:12       at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1021)
05/05/06 15:11:12       at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1841)
05/05/06 15:11:12       at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1819)
LeanMoreTryMoreAsked:
Who is Participating?
 
KuldeepchaturvediCommented:
>Where exactly did you copy them to?
you are suppose to have them in web-inf/lib of your webapp..
 and as dave is saying you need
mail.jar
activation.jar
mailapi.jar
smtp.jar
imap.jar to get it to work

( all in lib directory)
0
 
objectsCommented:
> but NOT working on servlet.

What does your servlet look like?
0
 
LeanMoreTryMoreAuthor Commented:
Tomcat.

But I run this inside Oracle JDeveloper 10g
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
objectsCommented:
No I meant what does the servlet code look like that is failing.
0
 
LeanMoreTryMoreAuthor Commented:
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax/mail/internet/AddressException
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
      org.apache.jsp.GBXcustomerRegister_005faction_jsp._jspService(org.apache.jsp.GBXcustomerRegister_005faction_jsp:79)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoClassDefFoundError: javax/mail/internet/AddressException

0
 
suprapto45Commented:
Hi,

have you included mail.jar in your classpath?

Regards
Dave
0
 
suprapto45Commented:
Hi,

I mean mail.jar from JavaMail lib.

Regards
Dave
0
 
LeanMoreTryMoreAuthor Commented:
I use the mail.jar provided from Oracle. mail.jar
0
 
suprapto45Commented:
Hi,

>>"it works running on server but NOT working on servlet."
Can you tell me more on it?

regards
Dave
0
 
objectsCommented:
Where have you put it?  Should either be in <webapp>/WEB-INF/lib or <tomcat>/common/lib
0
 
objectsCommented:
> it works running on server but NOT working on servlet.

That stack trace is actually from your jsp
0
 
LeanMoreTryMoreAuthor Commented:
The java program used for sending email is run on our NT2003 Server. It works. NOTES. The mail.jar and activation.jar are given from SUN..NOT USE the Oracle one.


s we will developed the web application using JSP, I take this java program run on the servlet. We are using Oracle JDeveloper10g to develop JSP and Java. It runs time error when it runs.

NOTES: I COPY THE mail.jar and activation.jar from SUN to Servlet and then shut down the Apache Tomcat and Re-start again, this time I DOES NOT SHOW any error but no email is received.


Thank you in advance for both obejct and suprapto45
0
 
suprapto45Commented:
Hi,

How about the rest *.jar from JavaMail such as smtp.jar, mailapi.jar, pop3.jar.

Have you included them?

Regards
Dave
0
 
objectsCommented:
> I COPY THE mail.jar and activation.jar from SUN to Servlet

Where exactly did you copy them to?
0
 
LeanMoreTryMoreAuthor Commented:
iT USED TO BE WORKING ON THE CLIENT SERVER where I only copied mail.jar and activation.jar

Where do i get the mailapi.jar, smtp.jar and imap.jar?

I copy to $TOMCAT_HOME/webapps/AAPL/WEB-INF/lib


0
 
KuldeepchaturvediCommented:
you can download all the mail components from here

http://java.sun.com/products/javamail/index.jsp
0
 
objectsCommented:
> java.lang.NoClassDefFoundError: javax/mail/internet/AddressException

AddressException is in mail.jar isn't it??
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.