Javamail problem
- From: "Camel" <jiao_he_99@xxxxxxxxx>
- Date: Wed, 27 Jul 2005 23:50:11 GMT
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.fallback", "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("me@xxxxxxxxxxxxxxx"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("him@xxxxxxxxx",false));
msg.setSubject("Hello");
msg.setText("How are you");
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println("Message sent.");
}
}
---------code end-------------------
.
- Prev by Date: Re: Style and practice question: use of interfaces
- Next by Date: Re: inhibiting comment reflow
- Previous by thread: inhibiting comment reflow
- Next by thread: Running RMI Server on Different Port - binding issues
- Index(es):
Relevant Pages
|