Getting exception while sending mail through Java
exception is::
Exception in thread "main" java.lang.NoSuchMethodError:
com.sun.mail.util.LineOutputStream.<init>(Ljava/io/OutputStream;Z)V
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1648)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1906)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1134)
at javax.mail.Transport.send0(Transport.java:255)
at javax.mail.Transport.send(Transport.java:124)
at com.yodlee.SendMail.sendMail(SendMail.java:78)
at com.yodlee.SendMail.main(SendMail.java:32)
Here is the Java code::
Properties props = new Properties();
props.put(SMTP_HOST_KEY,SMTP_HOST);
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(".....",
"#.......");
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(RECIPIENT_FROM));
message.setSubject(SUBJECT);
message.setSentDate(new Date());
//message.setText("Test mails111");
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(data, "text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
status = -1;
throw new RuntimeException(e);
}
I am getting error at Transport.send(msg); Jars i am using here:: smtp 1.6.0, Javax Mail 1.4.7 , mailactivation
Most likely you have multiple versions of the JavaMail classes on your class path. Check all your dependencies and your application server environment for conflicts. If more than one jar file contains the javax.mail.* or com.sun.mail.* classes, you have a problem.
And be sure to fix all these common JavaMail mistakes, and definitely be sure to use the latest version of JavaMail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With