I’m trying to learn javamail. I did a web page to test it.
my code:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class Sendemail {
public static void main(String [] args) {
String from="carcaharas@hotmail.com";
String to="carcaharas@yahoo.com";
//String smtpHost = "smtp.auna.com";
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.ono.com");
Session sesion = Session.getDefaultInstance(props,null);
try {
Message message = new MimeMessage(session);
message.setSubject("Hello world");
message.setFrom(new InternetAddress(from));
message.addRecipient( Message.RecipientType.TO,
new InternetAddress(to));
message.setText("this is the body of the message ");
Transport.send(message);
} catch (MessagingException e) {
System.error.println(e.getMessage());
}
}
}
and the error is:
java.lang.NoClassDefFoundError: javax/activation/DataSource
Exception in thread "main"
the problem is in the line
Message message = new MimeMessage(session);
any ideas?