Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Throws javax.mail.NoSuchProviderException: smtp

843830Feb 9 2007 — edited Sep 19 2007
Hi guys
This is my first post. I am trying to send an email using Apache commons mail in SendEmail. I have masked the SMTP server name & i am using TestEmail to pass values to it. The error doesnot show up if i comment the smail.send(). (so thats where the problem lies)
I have added the required jar files in the classpath commons-email-1.0.jar, mail.jar, activation.jar, smtp.jar
    
package email;
import java.util.HashMap;
import org.apache.commons.mail.*;
public class SendEmail {

    public boolean sendEmail(HashMap emaildetails)
    {
        SimpleEmail smail = new SimpleEmail();
        try {
            smail.setHostName("XXX.XXXX.com");
            smail.addTo((String)emaildetails.get("emailto"));
            smail.setFrom((String)emaildetails.get("emailfrom"));
            smail.setSubject((String)emaildetails.get("emailsubject"));
            smail.setMsg((String)emaildetails.get("emailmsg"));
            smail.send();
         } catch (EmailException e) {
            e.printStackTrace(System.err);
          }
         return true;
     }
}
the console throws this error
org.apache.commons.mail.EmailException: Sending the email to the following server failed : XXX.XXXX.com:25
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:873)
	at org.apache.commons.mail.Email.send(Email.java:898)
	at email.SendEmail.sendEmail(SendEmail.java:25)
	at email.TestEmail.main(TestEmail.java:32)
Caused by: javax.mail.NoSuchProviderException: smtp
	at javax.mail.Session.getService(Session.java:611)
	at javax.mail.Session.getTransport(Session.java:541)
	at javax.mail.Session.getTransport(Session.java:484)
	at javax.mail.Session.getTransport(Session.java:464)
	at javax.mail.Session.getTransport(Session.java:519)
	at javax.mail.Transport.send0(Transport.java:155)
	at javax.mail.Transport.send(Transport.java:81)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:863)
	... 3 more
i had problems with the jar files not being compatible with the latest commons email jar files,so i replaced the following jar files:- mail.jar, activation.jar, smtp.jar with the previous versions thats how i got this far. All help will be appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2007
Added on Feb 9 2007
7 comments
2,622 views