Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Javamail problem

Reply
Thread Tools

Javamail problem

 
 
Camel
Guest
Posts: n/a
 
      07-27-2005
Hi All,

I am tring to send email through my smtp server over SSL connection. I know
the mail server requires SSL. When I run my program, I got:
SSLException: Unrecognized SSL message, plaintext connection?

What is the problem? any clues?

Thank you inadvance.


Below is my program:

------------code begin-----------
import java.security.Security;
import java.util.Date;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
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 MailSender {

public static void main(String[] args) throws AddressException,
MessagingException {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", "mail.myhost.com");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallbac k", "false");
props.setProperty("mail.smtp.port", "26");
props.setProperty("mail.smtp.socketFactory.port", "26");
props.put("mail.smtp.auth", "true");
final String username = "myUserName";
final String password = "myPass";
Session session = Session.getDefaultInstance(props, new
Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

// -- Create a new message --
Message msg = new MimeMessage(session);

// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(""));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("",false));
msg.setSubject("Hello");
msg.setText("How are you");
msg.setSentDate(new Date());
Transport.send(msg);

System.out.println("Message sent.");
}
}

---------code end-------------------


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaMail sending problem and solution Bobby Martin Java 4 05-21-2004 01:57 AM
Problem about JavaMail mrby Java 1 04-29-2004 06:39 PM
problem sending javamail Nilambari Java 2 12-26-2003 08:27 AM
q javamail compile problem Jason Java 3 12-19-2003 12:34 AM
No header retrieved problem solved for javamail news Java 0 10-31-2003 04:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57