Javamail problem

Discussion in 'Java' started by Camel, Jul 28, 2005.

  1. Camel

    Camel Guest

    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(""));
    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-------------------
    Camel, Jul 28, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news
    Replies:
    0
    Views:
    335
  2. Jason

    q javamail compile problem

    Jason, Dec 15, 2003, in forum: Java
    Replies:
    3
    Views:
    392
    Jason
    Dec 19, 2003
  3. Nilambari

    problem sending javamail

    Nilambari, Dec 23, 2003, in forum: Java
    Replies:
    2
    Views:
    8,312
    Ulas Ergin
    Dec 26, 2003
  4. mrby

    Problem about JavaMail

    mrby, Apr 29, 2004, in forum: Java
    Replies:
    1
    Views:
    461
    GaryM
    Apr 29, 2004
  5. Bobby Martin

    JavaMail sending problem and solution

    Bobby Martin, May 19, 2004, in forum: Java
    Replies:
    4
    Views:
    5,735
    Bobby Martin
    May 21, 2004
Loading...

Share This Page