Results 1 to 1 of 1
  1. #1
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Rep Power

    Default Email send problem

    I have created a servlet which sends the mail to my mail
    All the libs mail.jar and activation.jar are in apche-tomcat libs folder,and also added to the Web Dynamic Project in Eclipse.I got such excpetion:
    Java Code:
    SEVERE: Servlet.service() for servlet SendEmail threw exception
    java.lang.SecurityException: Access to default session denied
    	at javax.mail.Session.getDefaultInstance(
    	at org.eclipse.http.SamSite.SendEmail.doPost(
    	at javax.servlet.http.HttpServlet.service(
    	at javax.servlet.http.HttpServlet.service(
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    	at org.apache.catalina.core.StandardWrapperValve.invoke(
    	at org.apache.catalina.core.StandardContextValve.invoke(
    	at org.apache.catalina.core.StandardHostValve.invoke(
    	at org.apache.catalina.valves.ErrorReportValve.invoke(
    	at org.apache.catalina.core.StandardEngineValve.invoke(
    	at org.apache.catalina.connector.CoyoteAdapter.service(
    	at org.apache.coyote.http11.Http11Processor.process(
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(

    here is the sendmail.html file:

    Java Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <form                    method=post              action="SendEmail">
                         Reciever        <input type=text name=text2><br>
                         Subject          <input type=text name=text3><br>
                        Message        <textarea name='area1' rows=5 cols=30>                  </textarea>
                                                 <input     type=submit>
    And SendMail servlet file code
    Java Code:
    package org.eclipse.http.SamSite;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.mail.*;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    import javax.mail.internet.*;   // important
    import javax.mail.event.*;      // important
    import java.util.*;
     * Servlet implementation class for Servlet: SendEmail
     public class SendEmail extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
       static final long serialVersionUID = 1L;
       private static final String SMTP_HOST_NAME = "";
       private static final String SMTP_AUTH_USER = "serjantik";
       private static final String SMTP_AUTH_PWD = "";
       private static final String fromEmailAddress="";
        /* (non-Java-doc)
    	 * @see javax.servlet.http.HttpServlet#HttpServlet()
    	public SendEmail() {
    	/* (non-Java-doc)
    	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    	/* (non-Java-doc)
    	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		PrintWriter  out=response.getWriter();
            boolean debug = false;
            Properties props = new Properties();
    		props.put("mail.transport.protocol", "smtp");
    		props.put("", SMTP_HOST_NAME);
    		props.put("mail.smtp.auth", "true");
    		Authenticator auth = new SMTPAuthenticator();
    		Session session = Session.getDefaultInstance(props, auth);
            String s2 = request.getParameter("text2");
            String s3 = request.getParameter("text3");
            String s4 = request.getParameter("area1");
    		// create a message
    		Message msg = new MimeMessage(session);
    			// set the from and to address
    			InternetAddress addressFrom = new InternetAddress(fromEmailAddress);
    			InternetAddress[] addressTo = new InternetAddress[]{new InternetAddress(s2)};
    			msg.setRecipients(Message.RecipientType.TO, addressTo);
    			// Setting the Subject and Content Type
    			msg.setContent(s4, "text/plain");
    		}catch(MessagingException err){
    			out.println("The message wasn't sent,some errors occured");
    	private class SMTPAuthenticator extends javax.mail.Authenticator {
    		public PasswordAuthentication getPasswordAuthentication() {
    			String username = SMTP_AUTH_USER;
    			String password = SMTP_AUTH_PWD;
    			return new PasswordAuthentication(username, password);
    What is wrong with SSL?
    Last edited by serjant; 09-19-2008 at 03:22 AM.

Similar Threads

  1. send email using JMS
    By Heather in forum Advanced Java
    Replies: 9
    Last Post: 01-07-2009, 04:04 PM
  2. Replies: 1
    Last Post: 09-27-2008, 02:42 AM
  3. help in email developing
    By reached in forum New To Java
    Replies: 0
    Last Post: 12-09-2007, 08:55 PM
  4. Email Sigs.
    By tomrayne in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 10:14 AM
  5. To send email of page present Web from a Jsp
    By Marcus in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-09-2007, 05:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts