JavaRanch » Java Forums »
Java »
Java in General
| Author |
Javamail Example Problem
|
Rohan Kalbhor
Ranch Hand
Joined: Aug 18, 2006
Posts: 78
|
|
Hello All, I tried this example on javamail ------------------------------------------------------------ import java.io.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import javax.net.ssl.*; public class SendApp { public static void send(String smtpHost, int smtpPort, String from, String to, String subject, String content) throws AddressException, MessagingException { java.util.Properties props = new java.util.Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "true"); props.put("mail.smtp.port", 465); 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("gmailid", "password"); } }); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); msg.setSubject(subject); msg.setText(content); Transport.send(msg); } public static void main(String[] args) throws Exception { // Send a test message send("smtp.gmail.com", 465, " rohanrkk@gmail.com", " rohanrkk@gmail.com ", "Hi !!!", "\nHow are you ?"); } } ---------------------------------------------------------- After i ran the code it gave the following errors --------------------------------------------------------- DEBUG: JavaMail version 1.4ea DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_01\jre\lib\ javamail.providers (The system cannot find the file specified) DEBUG: !anyLoaded DEBUG: not loading resource: /META-INF/javamail.providers DEBUG: successfully loaded resource: /META-INF/javamail.default.providers DEBUG: Tables of loaded providers DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax .mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsyste ms, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com .sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLSt ore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsyst ems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.su n.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=jav ax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP 3Store,Sun Microsystems, Inc]} DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com. sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STOR E,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Prov ider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems , Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.S MTPTransport,Sun Microsystems, Inc]} DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map DEBUG: !anyLoaded DEBUG: not loading resource: /META-INF/javamail.address.map DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_01\jre\lib\ javamail.address.map (The system cannot find the file specified) DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s mtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? Exception in thread "main" javax.mail.MessagingException: Exception reading resp onse; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connecti on? at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java :1462) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:37 0) at javax.mail.Service.connect(Service.java:297) at javax.mail.Service.connect(Service.java:156) at javax.mail.Service.connect(Service.java:105) at javax.mail.Transport.send0(Transport.java:168) at javax.mail.Transport.send(Transport.java:98) at SendApp.send(sendapp.java:47) at SendApp.main(sendapp.java:52) Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext conne ction? at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRec ord.java:501) at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:343) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.j ava:720) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SS LSocketImpl.java:1025) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketIm pl.java:675) at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java: 75) at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read(BufferedInputStream.java:235) at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75) at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java :1440) ------------------------------------------------------------------- Please do help me ,how to get rid of this problem Thanks in Advance Rohan Kalbhor
|
..............................<br />Exceptions are a part of possibility<br />Errors are a part of truth<br />................................
|
 |
Sidd Kulk
Ranch Hand
Joined: Feb 20, 2007
Posts: 152
|
|
Please don't post the same topic in more than one threads. Help maintain the decorum of Java Ranch. Sid
|
 |
Ajay Singh
Ranch Hand
Joined: Dec 13, 2006
Posts: 182
|
|
|
You need to enable SSL on the connection
|
 |
Rohan Kalbhor
Ranch Hand
Joined: Aug 18, 2006
Posts: 78
|
|
Thankyou Ajay for giving your opinion, ca you please help me ,as to how can i enable the SSL connection Thanks in Advance
|
 |
 |
|
|
subject: Javamail Example Problem
|
|
|
|