Can't send to a gmail account

So I started looking at JavaMail today and came up with this.

import java.util.Properties;

import java.security.Security;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

publicclass MailClient

{

privatestaticfinal String[] recipient ={"********@gmail.com"};

publicstaticvoid main(String args[])throws Exception

{

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

new MailClient().sendMessage(recipient,"Testing","Testing123...","*******@gmail.com");

}

publicvoid sendMessage(String recipients[], String subject, String message, String from)throws MessagingException

{

Properties props =new 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()

{

returnnew PasswordAuthentication("********","********");

}

});

session.setDebug(true);

Message msg =new MimeMessage(session);

InternetAddress addressFrom =new InternetAddress(from);

msg.setFrom(addressFrom);

InternetAddress[] addressTo =new InternetAddress[recipients.length];

for (int i = 0; i < recipients.length; i++)

{

addressTo[i] =new InternetAddress(recipients[i]);

}

msg.setRecipients(Message.RecipientType.TO, addressTo);

msg.setSubject(subject);

msg.setContent(message,"text/plain");

Transport.send(msg);

}

}

It gives me the following debugging info and exception.

DEBUG: JavaMail version 1.4ea

DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_12\lib\javamail.providers (The system cannot find the file specified)

DEBUG: URL jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/imap.jar!/META-INF/javamail.providers

DEBUG: successfully loaded resource: jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/imap.jar!/META-INF/javamail.providers

DEBUG: URL jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/pop3.jar!/META-INF/javamail.providers

DEBUG: successfully loaded resource: jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/pop3.jar!/META-INF/javamail.providers

DEBUG: URL jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/smtp.jar!/META-INF/javamail.providers

DEBUG: successfully loaded resource: jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/smtp.jar!/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 Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.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.POP3Store,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[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsy stems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc]}

DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map

DEBUG: URL jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/smtp.jar!/META-INF/javamail.address.map

DEBUG: successfully loaded resource: jar:file:/C:/Program%20Files/Java/javamail-1.4/lib/smtp.jar!/META-INF/javamail.address.map

DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_12\lib\javamail.address.map (The system cannot find the file specified)

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.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 465, isSSL false

220 mx.google.com ESMTP c23sm10209667ana

DEBUG SMTP: connected to host "smtp.gmail.com", port: 465

EHLO Kyle-PC

250-mx.google.com at your service, [72.73.20.55]

250-SIZE 28311552

250-8BITMIME

250-AUTH LOGIN PLAIN

250 ENHANCEDSTATUSCODES

DEBUG SMTP: Found extension "SIZE", arg "28311552"

DEBUG SMTP: Found extension "8BITMIME", arg ""

DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"

DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

DEBUG SMTP: Attempt to authenticate

AUTH LOGIN

334 VXNlcm5hbWU6

Tm8hRm9ydHJlc3M=

334 UGFzc3dvcmQ6

Tm8hRm9ydHJlc3M=

535 5.7.1 Credentials Rejected c23sm10209667ana

Exception in thread"main" javax.mail.AuthenticationFailedException

at javax.mail.Service.connect(Service.java:306)

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 emailtest.MailClient.sendSSLMessage(MailClient.java:61)

at emailtest.MailClient.main(MailClient.java:24)

Any idea on what is going on? Thanks in advance.

[8717 byte] By [Rob_Ha] at [2007-11-27 10:39:09]
# 1

See http://www.rgagnon.com/javadetails/java-0570.html

for a more simpler way.

Since GMail port is SSL-enabled, you need JavaMail 1.4 or better.

bye.

--

http://www.rgagnon.com/howto.html

RealHowToa at 2007-7-28 18:59:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

> Since GMail port is SSL-enabled, you need JavaMail

> 1.4 or better.

I have version 1.4.

Rob_Ha at 2007-7-28 18:59:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

It's probably not using your socket factory so it's probably not using SSL

when it connects. See the JavaMail FAQ for a simpler way to do it.

bshannona at 2007-7-28 18:59:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

> It's probably not using your socket factory so it's

> probably not using SSL

> when it connects. See the JavaMail FAQ for a simpler

> way to do it.

I looked at the FAQ, but I can't use command line arguments. Is there anyway of fixing my class so it will work properly? Thanks again.

Rob_Ha at 2007-7-28 18:59:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Did you check my check my example ?

From your debug output, "isSSL" is false.

it's because you don't set the right properties.

props.put("mail.transport.protocol", "smtps");

props.put("mail.smtps.host", SMTP_HOST_NAME);

props.put("mail.smtps.auth", "true");

--

http://www.rgagnon.com/howto.html

RealHowToa at 2007-7-28 18:59:14 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

> I looked at the FAQ, but I can't use command line

> arguments. Is there anyway of fixing my class so it

> will work properly? Thanks again.

Apparently this is a big mystery to people.

You don't have to use command line parameters. The examples just

show how to use existing, known to work, programs. The command

line parameters, along with the source code for those programs, shows

how to set the properties you'll need to set in your own program.

I guess I'm going to have to update the examples to include the lines

of Java code that correspond to the command line parameters so it's

more obvious to people how to copy the settings into their own programs.

bshannona at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

> Did you check my check my example ?

No, I missed it. I just ran the code and it worked perfectly. Thanks again.

Rob_Ha at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

> The command

> ine parameters, along with the source code for those

> programs, shows

> how to set the properties you'll need to set in your

> own program.

Sorry, I didn't even think to try that. Thanks again for both of your help.

Rob_Ha at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

Hi, i've tried out your example by editing my email address and password, andwhen i execute it, it gave me an exception :

DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unsupported record version Unknown-50.49

Exception in thread "main" javax.mail.MessagingException: Exception reading response;

nested exception is:

javax.net.ssl.SSLException: Unsupported record version Unknown-50.49

at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)

at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:645)

at SimpleSSLMail.test(SimpleSSLMail.java:41)

at SimpleSSLMail.main(SimpleSSLMail.java:15)

Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-50.49

at com.sun.net.ssl.internal.ssl.InputRecord.readV3Record(InputRecord.java:375)

at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:360)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:722)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:679)

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:237)

at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)

at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)

... 3 more

Process completed.

However, the mail was successfully sent. I'm not good at networking, so i'm not sure what happened here. How do i fix it so that it doesnt give me this stack trace?

Thanks.

TrAnScEnD3nTa at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10

You posted this same question to this other thread:

http://forum.java.sun.com/post!reply.jspa?messageID=9774101

bshannona at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

I've downloaded a free smtp server on my PC.. however i am unable to send it to my email accounts. It looks like the servers on the other side doesnt accept mails from my pc ?

As my school blocks the connections, i couldnt use gmail's smtp server to send mail (I need to send at school)

is it due to the server i downloaded ? Are there any alternatives? I'm really lost...

TrAnScEnD3nTa at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12

please refer

http://forum.java.sun.com/thread.jspa?threadID=5196042&tstart=0

same exception came for me too

jimmy@banga at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 13

Try to add the following property:

props.put("mail.smtps.quitwait", "false");

// props.put("mail.smtp.quitwait", "false");

--

http://www.rgagnon.com/howto.html

RealHowToa at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 14

Setting up and running your own mail server is a topic that's well beyond

what we can cover in this forum.

bshannona at 2007-7-28 18:59:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...