Javamail problem



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-------------------


.



Relevant Pages

  • Re: Outlook Script to Send email
    ... I ended up using stunnel for SSL and BLAT to send the email. ... The server requires authentication box is checked. ... If you hit the SMTP server without authentication, ...
    (microsoft.public.scripting.vbscript)
  • Re: Preventing tunnels through HTTPS proxies
    ... Alternatively playing a man-in-the-middle on the proxy, ... but also the matter of the stuff in SSL certificate matching the ... look up the SSL handshake procedure) you were able to distinguish SSL ... How can you tell HTTP traffic over SSL connection from any other ...
    (Security-Basics)
  • Re: Can SSL sessions be compromised?
    ... us to use their computers for internet access to our headquarters. ... etc) attachments using webmail during these SSL sessions. ... Depends on the endpoints of the SSL connection. ... proxy server, then be aware that they can read everything. ...
    (comp.security.misc)
  • Re: Mail Error 5530: The server doesnt support SMTP authentication.
    ... Using SSL with a SMTP server that requires SMTP authentication doesn't work ... It's a known bug in Entourage X. ... > POP set for SSL ...
    (microsoft.public.mac.office.entourage)
  • Re: SSL for SMTP tests ?
    ... Since his ISP blocks outbound port 25, he needs to use SSL to ... communicate with the remote SMTP server (where, once in, he ... authenticates with username/password). ... I'm glad to hear that _someone's_ ISP blocks port 25. ...
    (comp.os.vms)