send mail code not work for java EE 5 web project

I am using myeclipse 7, where i have added java EE 5 libraries witch i required.If i add the mail.jar externally to the application, it calling the javaee.jar from java EE 5 libraries.It’s not using the mail.jar.If i remove java EE 5 libraries then it is working, But i require java EE 5 libraries. How can i send mail using javaee.jar of java EE 5 library?.

If it require below is my hava code for sed mail

 String  d_email = "[email protected]",
                d_password = "pass",
                d_host = "",
                d_port  = "465",
                m_to = "[email protected]",
                m_subject = "Testing",
                m_text = "This is the testing email.";

        public Main()
            Properties props = new Properties();
            props.put("mail.smtp.user", d_email);
            props.put("", d_host);
            props.put("mail.smtp.port", d_port);
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.debug", "true");
            props.put("mail.smtp.socketFactory.port", d_port);
            props.put("mail.smtp.socketFactory.class", "");
            props.put("mail.smtp.socketFactory.fallback", "false");

            SecurityManager security = System.getSecurityManager();

                Authenticator auth = new SMTPAuthenticator();
                Session session = Session.getInstance(props, auth);

                MimeMessage msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(d_email));
                msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));

                System.out.println("Mail Sent");
            catch (Exception mex)

    public static void main(String[] args)
        Main blah = new Main();

    private class SMTPAuthenticator extends javax.mail.Authenticator
        public PasswordAuthentication getPasswordAuthentication()
            return new PasswordAuthentication(d_email, d_password);

Error :

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
    at javax.mail.Session.loadProvidersFromStream(
    at javax.mail.Session.access$000(
    at javax.mail.Session$1.load(
    at javax.mail.Session.loadResource(
    at javax.mail.Session.loadProviders(
    at javax.mail.Session.<init>(
    at javax.mail.Session.getInstance(
    at com.ctn.origin.connection.Main.<init>(
    at com.ctn.origin.connection.Main.main(


You should not manually add container specific libraries like javaee.jar to your project. It would only lead to runtime troubles if you deploy and run the project on a container of a different make/version. The javaee.jar is specific to Glassfish. Since Glassfish by itself already ships with a mail.jar this suggests that your target runtime is not Glassfish at all. It’s probably Tomcat or JBoss or something.

If you did this to overcome project compilation errors, you should have solved this differently. I don’t do MyEclipse, but I believe this is much similar to Eclipse, so this Eclipse based answer should work out for MyEclipse as well: rightclick the project, choose Properties, go to Target Runtime section and select the target runtime (the servletcontainer which you’d like to use) from the list. This way Eclipse will automatically include its libraries in the project’s build path the right way.

See also:

Leave a Reply

Your email address will not be published. Required fields are marked *