Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:53:22+00:00 2026-06-17T21:53:22+00:00

I am trying to run a program to send mail using javamail. it compiles

  • 0

I am trying to run a program to send mail using javamail.

it compiles successfully,but when i run it gives the below mentioned error.

Exception in thread “main” java.lang.NoClassDefFoundError: javamail1_4_5/SendEma
il (wrong name: SendEmail)

questions

  1. Is there any settings required to run this program except copying mail.jar and activation.jar in classpath.i have copied those 2 files in C:\Program Files\Java\jdk1.7.0\jre\lib\ext and the .java file is in java\jdk1.7.0\bin folder.

2.Is there any server required to execute this program?

this is the code

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {    
      // Recipient's email ID needs to be mentioned.
      String to = "abc@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "xyz@gmail.com";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:53:23+00:00Added an answer on June 17, 2026 at 9:53 pm

    java.lang.NoClassDefFoundError: javamail1_4_5/SendEmail (wrong name: SendEmail)

    This basically means that you’ve placed the class file in a folder named javamail1_4_5 and that you were trying to run it as java javamail1_4_5.SendEmail. This class is expected to have a package declaration which matches the folder.

    package javamail1_4_5;
    

    However, the name SendEmail in the error message hints that there’s no package at all. You have 2 options:

    1. Add that package declaration to top of the class (and recompile).
    2. cd into the javamail1_4_5 folder and execute it instead by java SendEmail.

    Unrelated to the concrete problem, putting arbitrary JAR files not related to JRE itself in JRE’s /lib or /lib/ext is a bad practice. It totally breaks portability. Use the -cp or -classpath argument or package it in a JAR. Use if necessary bat/cmd files save repeated commands. Putting source/class files in JRE’s installation folder makes also no sense. You’re not required to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run a program and SOMETIMES I'm getting this error when
When i am trying to run my program it is giving the following error
I have this problem when trying to run hello world program using android SDK.
I'm trying to build a basic POP3 mail client in C/++, but I've run
I'm trying to send an email using JavaMail API. I have jdk 1.5 installed
The following is the program, which I am trying to send e-mail. The code
So I have this very basic program that is trying to send an e-mail,
I am trying to build a program that can send TCP packets, but when
When I run the program I get an invalid IP address error. I'm trying
I am trying to send an email from a C++ program using imap library.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.