File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Javamail Example Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Javamail Example Problem" Watch "Javamail Example Problem" New topic

Javamail Example Problem

Rohan Kalbhor
Ranch Hand

Joined: Aug 18, 2006
Posts: 78
Hello All,
I tried this example on javamail
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

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("", "");
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", "");
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));


public static void main(String[] args) throws Exception {
// Send a test message
send("", 465, "", " ",
"Hi !!!", "\nHow are you ?");

After i ran the code it gave the following errors
DEBUG: JavaMail version 1.4ea
DEBUG: 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,
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],
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/
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/
DEBUG: C:\Program Files\Java\jdk1.5.0_01\jre\lib\ (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 "", port 25, isSSL false
DEBUG SMTP: exception reading response: Unrecognized
SSL message, plaintext connection?
Exception in thread "main" javax.mail.MessagingException: Exception reading resp
nested exception is: Unrecognized SSL message, plaintext connecti
at com.sun.mail.smtp.SMTPTransport.readServerResponse(
at com.sun.mail.smtp.SMTPTransport.openServer(
at com.sun.mail.smtp.SMTPTransport.protocolConnect(
at javax.mail.Service.connect(
at javax.mail.Service.connect(
at javax.mail.Service.connect(
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at SendApp.send(
at SendApp.main(
Caused by: Unrecognized SSL message, plaintext conne
at com.sun.mail.util.LineInputStream.readLine(
at com.sun.mail.smtp.SMTPTransport.readServerResponse(
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.

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
I agree. Here's the link:
subject: Javamail Example Problem