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.
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.