function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MSchumacherMSchumacher 

get error javax.email.nosuchproviderexception: smtp when sending email from a java app

Prior to API7.x, I was able to send email using the following code using Exclipse.
 

Properties props = System.getProperties();

props.put("mail.smtp.host", "mail.idcnet.com");

props.put("mail.smtp.port", "25");

props.put("mail.transport.protocol","smtp");

Session session = Session.getInstance(props, null);

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));

msg.setSentDate(new Date());

msg.setSubject(subject);

MimeMultipart mimeMultipart = new MimeMultipart();

// Add the Text Body Content to the Multipart

MimeBodyPart text=new MimeBodyPart();

text.setContent(body,"text/plain");

// Add the Body Content to the MultiPart Mime

mimeMultipart.addBodyPart(text);

//Add the Image Content to the Multipart

MimeBodyPart mimeBodyPart = new MimeBodyPart();

File file = new File (DSRptFile);

FileDataSource fds = new FileDataSource(file);

DataHandler dh = new DataHandler(fds);

mimeBodyPart.setFileName(file.getName());

mimeBodyPart.setDisposition(Part.ATTACHMENT);

mimeBodyPart.setDescription("Attached file: " + file.getName());

mimeBodyPart.setDataHandler(dh);

// Add the Image Content to the MultiPart

mimeMultipart.addBodyPart(mimeBodyPart);

// Add the whole Multipart into the Message

msg.setContent(mimeMultipart);

Transport.send(msg);

}catch(Exception e){

System.out.println("sendEmail()"+ e.toString());

}

 

I am now using the version 7 API and I noticed that the activation.jar and mailapi.jar were included in the libraries. I have them in my project but receive the error below.  Any suggestions?

javax.mail.NoSuchProviderException: smtp

at javax.mail.Session.getService(Session.java:750)

at javax.mail.Session.getTransport(Session.java:689)

at javax.mail.Session.getTransport(Session.java:632)

at javax.mail.Session.getTransport(Session.java:612)

at javax.mail.Session.getTransport(Session.java:667)

at javax.mail.Transport.send0(Transport.java:154)

at javax.mail.Transport.send(Transport.java:80)