abooysen2
asked on
Java Mail
Hi Expert
I have a sample code that sends out mail but I got this Error
Exception in thread "main" java.lang.NoClassDefFoundE rror: javax/activation/DataSourc e
at MailClient.sendMail(MailCl ient.java: 21)
at MailClient.main(MailClient .java:55)
it's failing at not sure why
Message message = new MimeMessage(session);
I have a sample code that sends out mail but I got this Error
Exception in thread "main" java.lang.NoClassDefFoundE
at MailClient.sendMail(MailCl
at MailClient.main(MailClient
it's failing at not sure why
Message message = new MimeMessage(session);
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activity.*;
import javax.sql.DataSource;
public class MailClient {
public void sendMail(String mailServer, String from, String to,
String subject, String messageBody) 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
// Put all message parts in the message
message.setContent(multipart);
// Send the message
Transport.send(message);
}
public static void main(String[] args) {
try {
MailClient client = new MailClient();
String server = "mailserver.com";
String from = "Anthonio.Booysen@investec.co.za";
String to = "Anthonio.Booysen@investec.co.za";
String subject = "Test";
String message = "Testing";
client.sendMail(server, from, to, subject, message);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it may be an invalid address as per the SMPT server you use, talk to your adminsitrator!
ASKER
I took the smtp server address from a other project and verified it with my outlook. Does this mean the firewall does not allow me to sent mails?
could be an authentication issue... check with mail server admin...
ASKER
ok Thanks
ASKER
javax.mail.SendFailedExcep
nested exception is:
class com.sun.mail.smtp.SMTPAddr
at com.sun.mail.smtp.SMTPTran
at com.sun.mail.smtp.SMTPTran
at javax.mail.Transport.send0
at javax.mail.Transport.send(
at MailClient.sendMail(MailCl
at MailClient.main(MailClient