Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with sending a simple mail

Status
Not open for further replies.

TyzA

Programmer
Jan 7, 2002
86
BE
Hi,

When I try to sent a mail, I get the following error(s):
- javax.servlet.ServletException: Servlet execution threw an exception
- java.lang.NoClassDefFoundError: javax/mail/Message
at mail.doGet(mail.java:18)

This is my classpath:

CLASSPATH=%CLASSPATH%;C:\Program Files\Apache Group\Tomcat 4.1\webapps\comparitel\WEB-INF\classes;C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar;C:\j2sdk1.4.1\javamail-1.3\mail.jar;C:\j2sdk1.4.1\jaf-1.0.2\activation.jar;.


And here is my code (Sorry if it's alot):
--------------------
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class sent{

public String address, sendHost, getHost, mailUser, mailPwd;

public sent ()
{
this.address = "";
this.getHost = "";
this.sendHost = "";
this.mailUser = "";
this.mailPwd = "";
}

public void sentMsg(String strSubject, String strMsg)throws MessagingException,
AddressException,
NoSuchProviderException,
IOException{

String mailer = "msgsend";

try
{
Properties props = System.getProperties();

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

// Get a Session object
Session session = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(address));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("webcreator@dezonk.be", false));
msg.setSubject(strSubject);
msg.setText(strMsg);

Transport.send(msg);

System.out.println("\nMail was sent successfully.");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}



This is the servlet from where I call the sent class:
------------------------------------------------------

import java.io.*;
import java.util.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.comparitel.core.*;

public class mail extends HttpServlet{

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

String mailer = "msgsend";
PrintWriter out = res.getWriter();
res.setContentType("text/html");

sent s = new sent();

ServletContext context = getServletContext();

String strHost = (String)context.getAttribute(Global.MAIL_HOST);
String strUsr = (String)context.getAttribute(Global.MAIL_USR);
String strPwd = (String)context.getAttribute(Global.MAIL_PWD);
String strSMTP = (String)context.getAttribute(Global.MAIL_SMTP);

try
{
String strMail = req.getParameter("email");
String strMsg = req.getParameter("msg");

s.address = strMail;
s.getHost = strHost;
s.sendHost = strSMTP;
s.mailUser = strUsr;
s.mailPwd = strPwd;

s.sentMsg("TEST", strMsg);
}
catch(Exception e)
{
e.printStackTrace();
}

// out.println("Mail Send");
}
}

I hope you guys can help, I've looked everywhere, but I can't find a solutions.

Thanks for any help,

T.
 
Message msg = new MimeMessage(session);

should be...

MimeMessage msg = new MimeMessage(session);
 
Hi idarke,

Sorry, but this didn't change anything.

I still get the same error.

T.
 
Sorry. When you shoot from the hip, sometimes you shoot yourself in the foot.

Did you get exactly the same error? ... or did the error now say
java.lang.NoClassDefFoundError: javax/mail/MimeMessage

Since Message and MimeMessage are both in the same jar file, it's hard to believe that one is found but not the other. Is it possible that you have another class of your own also called Message?


 
You're right. It's not the same error.
What I HAVE NOW IS/
java.lang.NoClassDefFoundError: javax/mail/Address
at mail.doGet(mail.java:21)

So i think this is something completely different.
Does it have something to do with the email address I parse in?

For your other question. I don't have another class called Message

T.
 
I've found the problem.

I forgot to put the mail.jar and activation.jar files in my webb-apps folder.

Now it works

Thanks anyway

T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top