Solved

Sending an email thru javax.mail. facing some problem

Posted on 2002-07-30
3
309 Views
Last Modified: 2013-11-24
hi
This is my code and when i run it i'm getting an error stating

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
        at MailTest.<init>(MailTest.java:31)
        at MailTest.main(MailTest.java:48)
I tried finding out other programs, but that doesn't give particualr exception.
i think the code is perfect
i didn't understand the "javax/activation/datasource"
 i need it very urgently.
i have attached my code also.


regards
Snehal

/*******************************************************/
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.Context;
import javax.naming.InitialContext;

public class MailTest
{
     String mailHost = "mail.business-functions.com";
     String to = "snehal@bfn.com";
     String from = "snehal@yahoo.com";
     String subject = "This is Test Mail Thru Java Mail API";
     String body = "This is Test Mail to check whether the Java Mail APi is Working or not. This is prototype developed by Snehal K gandhi of Business Functions Software Solutions Pvt Ltd.";
     Provider provider;

     public MailTest()
     {
          try
          {
               Properties props = System.getProperties();
               props.put("mail.smtp.host", mailHost);
               Session session = Session.getInstance(props,null);
               Message message = new MimeMessage(session);
               message.setFrom(new InternetAddress(from));
               message.setRecipients(Message.RecipientType.TO,new InternetAddress[]{new InternetAddress(to)});
               message.setSubject(subject);
               message.setContent(body, "text/plain");
               Transport.send(message);
               System.out.println("Mail has been Sent");
          }
          catch(MessagingException me)
          {
               System.out.println("2. Error While Sending the Mail and the exception is : " + me.toString());
          }

     }

     public static void main(String arg[])
     {
          new MailTest();
     }
}

/*******************************************************/
0
Comment
Question by:snehalkgandhi
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 7187353
You need activation.jar which can be downloaded at:
http://java.sun.com/products/javabeans/glasgow/jaf.html
0
 

Author Comment

by:snehalkgandhi
ID: 7187522
Thank u

regards
Snehal
0
 
LVL 92

Expert Comment

by:objects
ID: 7187538
Only a 'B' ??
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
table example 4 32
hibernate insert example 13 34
maven module vs maven project 3 46
Need help aligning JRadioButton that put in a box using GridBagLayout 2 16
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question