Using Java to send emails on gmail account
<p>I know this question is asked before but I think it was 2-3 years before and things have changed since then. None of the code samples is working now.
I am trying the following code in Java 1.6:</p>

<pre><code>Properties props = new Properties();
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("uname","password");
    }
});
session.setDebug(true);
Transport transport = session.getTransport();
InternetAddress addressFrom = new InternetAddress("abc@gmail.com");
MimeMessage message = new MimeMessage(session);
message.setSender(addressFrom);

for (int j = 0; j &lt; 20; j++) {
    message.setSubject("Testing javamail plain"+Math.random());
    message.setContent("This is a test", "text/plain");
    String sendTo [] = {"abc@gmail.com"};
    if (sendTo != null) {
        InternetAddress[] addressTo = new InternetAddress[sendTo.length];
        for (int i = 0; i &lt; sendTo.length; i++) {
            addressTo[i] = new InternetAddress(sendTo[i]);
        }
        message.setRecipients(Message.RecipientType.TO, addressTo);
    }
    transport.connect();
    Transport.send(message);
    transport.close();
    System.out.println("DONE");
}
</code></pre>

<p>and it throws this exception:</p>

<pre><code>org.apache.cxf.interceptor.Fault: javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:164)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:91)
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
java.util.concurrent.FutureTask.run(FutureTask.java:138)
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:218)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:161)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:112)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
</code></pre>

<p>I am using tomcat as webserver and cxf framefork for webservices.
Any help is much appreciated.</p>
