Hi i am unable to send mail from yahoo mail id.can any one help on this?

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.Properties;
public class MailClient
  public void sendMail(String mailServer, String from, String to,
                             String subject, String messageBody,
                             String[] attachments) throws
MessagingException, AddressException
         // Setup mail server
         Properties props = System.getProperties();
         props.put("mail.smtp.host", mailServer);
         // Get a mail session
         Session session = Session.getDefaultInstance(props, null);
         // Define a new mail message
         Message message = new MimeMessage(session);
         message.setFrom(new InternetAddress(from));
         message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
         message.setSubject(subject);
         // Create a message part to represent the body text
         BodyPart messageBodyPart = new MimeBodyPart();
         messageBodyPart.setText(messageBody);
         //use a MimeMultipart as we need to handle the file attachments
         Multipart multipart = new MimeMultipart();
         //add the message body to the mime message
         multipart.addBodyPart(messageBodyPart);
         // add any file attachments to the message
         addAtachments(attachments, multipart);
         // Put all message parts in the message
         message.setContent(multipart);
         // Send the message
         Transport.send(message);
     protected void addAtachments(String[] attachments, Multipart multipart)
                     throws MessagingException, AddressException
         for(int i = 0; i<= attachments.length -1; i++)
             String filename = attachments;
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
//use a JAF FileDataSource as it does MIME type detection
DataSource source = new FileDataSource(filename);
attachmentBodyPart.setDataHandler(new DataHandler(source));
//assume that the filename you want to send is the same as the
//actual file name - could alter this to remove the file path
attachmentBodyPart.setFileName(filename);
//add the attachment
multipart.addBodyPart(attachmentBodyPart);
public static void main(String[] args)
try
MailClient client = new MailClient();
String server="pop3.yahoo.com";
String from="[email protected]";
String to = "[email protected]";
String subject="Test";
String message="Testing";
String[] filenames = {"c:\\gopi.txt"};
client.sendMail(server,from,to,subject,message,filenames);
catch(Exception e)
e.printStackTrace(System.out);     
while compliling this one its compiled succesfully but i am getting exception at run time like..D:\mail>java MailClient
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/activation/re
gistries/MailcapFile
at javax.activation.MailcapCommandMap.loadFile(MailcapCommandMap.java:275)
at javax.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:128)
at javax.activation.CommandMap.getDefaultCommandMap(CommandMap.java:44)
at javax.activation.DataHandler.getCommandMap(DataHandler.java:136)
at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:568)
at javax.activation.DataHandler.getContent(DataHandler.java:501)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1253)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2012)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1980)
at javax.mail.Transport.send(Transport.java:97)
at MailClient.sendMail(MailClient.java:35)
at MailClient.main(MailClient.java:72)
can any one help on this....plz
thanks in advance
Edited by: Konapalli.Gopi on May 20, 2010 5:42 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Something's wrong with your CLASSPATH.
If you're not using JDK 6, you need to include activation.jar in your CLASSPATH.
If you've got any other jar files that define the javax.mail.* or javax.activation.* classes
in your CLASSPATH (such as javaee.jar or j2ee.jar), remove them.

Similar Messages

Maybe you are looking for

  • Report Layout in report Painter

    I created a Report in reportPainter. In the report layout, lead column section..I select Group Name to display the group name (set's id) in the report's lead column but not all the set's keys appear. It only appears children's ids but not the father'

  • I recently changed apple ids on my iphone and now can not update or download any apps

    I recently had an issue with my apple id and icould. I deleted my original apple id and made a new one with my new email address. I updated my phone with the info but now cannot update any apps on my phone and I cannot download any new apps? HELP!!!!

  • Getting the error while loading the master data

    Hi i have tried to delete the master data using right click and delete master data, but still there are data. Now i am trying to load this master data again then i am getting the message "0 from 50033 records" and data load got failed with error mess

  • Video adapters?

    does anyone know of an adapter that will go between a monitor's video cable and the mac vga adapter that will allow video to both the mac's monitor and another screen? I am trying to make it to where I can have my mac be my dvd player and work with m

  • Scripts for CS6 Scripting Guide

    The link in the PDF document "Adobe InDesign CS6 Scripting Guide:Javascript" is broken and I can't find the file with the example javascripts.  Can you help? /f