I read and tried the whole solution mentioned in stackoverflow and other sites, but still getting the problem and getting an exception.
The code:
import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class sendmail { Properties emailProperties; Session mailSession; MimeMessage emailMessage; public static void main(String args[]) throws AddressException, MessagingException { sendmail javaEmail = new sendmail(); javaEmail.setMailServerProperties(); javaEmail.createEmailMessage(); javaEmail.sendEmail(); } public void setMailServerProperties() { String emailPort = "587";
When I debug the code, it stops working on the line: Transport transport = mailSession.getTransport ("smtp");
I added the following JARs:
Mail.jar, pop3.jar, smtp-1.4.2.jar, Activation.jar, optional .jar
Full exception:
An exception is thrown in the main thread javax.mail.NoSuchProviderException: smtp in javax.mail.Session.getService (Session.java:764) in javax.mail.Session.getTransport (Session.java:689) in javax.mail.Session. getTransport (Session.java:632) in javax.mail.Session.getTransport (Session.java:612) in javax.mail.Session.getTransport (Session.java:667) on javax.mail.Transport.send0 (Transport.java : 154) on javax.mail.Transport.send (Transport.java:80) in JannyaPaid_Device.sendmail.sendEmail (sendmail.java:68) in JannyaPaid_Device.sendmail.main (sendmail.java:26)
Also I want to ask what can a firewall prevent these things from sending mail? Since we have a firewall installed, but I can manually open and send thrugh gmail mail.
source share