import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.activation.*;
import javax.swing.text.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import javax.activation.DataSource;
import javax.mail.internet.MimeMessage;
/**
*
* @author rathit
*/
public class SendMail {
/** Creates a new instance of SendMail */
public SendMail() {
}
private class SMTPAuthenticator extends javax.mail.Authenticator{
public PasswordAuthentication getPasswordAuthentication(){
String username = "Muni";
String password = "Raj";
return new PasswordAuthentication(username, password);
}
}
public void postMail() throws MessagingException {
boolean debug = false;
String recipients[] = {"java.muni@rediffmail.com"};
String recipientsCC[] = {"likhis_007@yahoo.com"};
String subject = "Mail";
String message = "This is body for the message";
String from = "pop_muni@yahoo.com";
Properties props = new Properties();
props.put("mail.smtp.host","208.220.245.70");//mail.yahoo.com/68.142.225.208
props.put("mail.smtp.auth","true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
MimeMessage msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for(int i = 0; i < recipients.length; i++){
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
//recipientsCC[]
InternetAddress[] addressCC = new InternetAddress[recipientsCC.length];
for(int j = 0; j < recipientsCC.length; j++){
addressCC[j] = new InternetAddress(recipientsCC[j]);
}
msg.setRecipients(Message.RecipientType.CC, addressCC);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
msg.setSubject(subject);
msg.setContent(message,"text/html");
Transport.send(msg);
System.out.println("Mail Successfully Sent");
}//End of postMail()
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws MessagingException {
// TODO code application logic here
new SendMail().postMail();
}
}
when run
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
at test.SendMail.postMail(SendMail.java:53)
at test.SendMail.main(SendMail.java:83)
Java Result: 1
pls help me