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

  • SEARCH
  • Home
  • 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 6196815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:42:28+00:00 2026-05-24T03:42:28+00:00

All I want to do is send an email in Java. Here is the

  • 0

All I want to do is send an email in Java. Here is the example I found:

import org.apache.commons.mail.SimpleEmail;

public class Email {

    public static void sendMessage(String emailaddress, String subject, String body) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setHostName("valid ip address here");
            email.addTo(emailaddress);
            email.setFrom("noreply@example.com", "No reply");
            email.setSubject(subject);
            email.setMsg(body);
            email.send();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

I immediately get the following exception on the SimpleEmail email = new SimpleEmail(); line:

java.lang.ClassNotFoundException: org.apache.commons.mail.SimpleEmail

I have the following JAR in my project (using Netbeans):
commons-email-1.2.jar

What am I doing wrong?

Thanks.

  • 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-05-24T03:42:28+00:00Added an answer on May 24, 2026 at 3:42 am

    Not sure why SimpleEmail didn’t work. But this did:

    import javax.mail.*;
      import javax.mail.internet.*;
    
      import java.util.Properties;
    
      public class Email {
    
         public static void sendMessage(String emailaddress, String subject, String body) {
            try {
               Properties props = new Properties();
               props.setProperty("mail.transport.protocol", "smtp");
               props.setProperty("mail.host", "myhost");
    
               Session mailSession = Session.getDefaultInstance(props, null);
               Transport transport = mailSession.getTransport();
    
               MimeMessage message = new MimeMessage(mailSession);
               message.setSubject("Testing javamail plain");
               message.setContent("This is a test", "text/plain");
               message.addRecipient(Message.RecipientType.TO, new InternetAddress("test@example.com"));
    
               transport.connect();
               transport.sendMessage(message,
                       message.getRecipients(Message.RecipientType.TO));
               transport.close();
            } catch (Exception ex) {
               ex.printStackTrace();
            }
         }
      }
    

    Thanks for the suggestions.

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

Sidebar

Related Questions

I want to send the same email to all of the users that have
Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov
I want to send Email in the background of the application. I dont want
I want to use ms sql 2005 to send email reminders to my customers.
in my webapplications whihc runs on tomcat on widows i want to send email
As the title said: Is it possible to send an email (using php mail())
I want to send an email in HTML5. I don't want to force the
I have a pretty simple Rails app and I want send an e-mail when
All I want is to be able to change the color of a bullet
All I want is to update an ListViewItem's text whithout seeing any flickering. This

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.