android下成功使用javamail发件QQ邮件、收件(SSL连接)

需要的包:mail.jar jsse.jar(说明:jsse.jar是jre自带的,如果jdk1.5及以下需要Java Activation Framework框架的activation.jar)

        //设置SSL连接、邮件环境
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());  
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";  
        Properties props = System.getProperties();
        props.setProperty("mail.smtp.host", "smtp.qq.com");
        props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.port", "465");
        props.setProperty("mail.smtp.socketFactory.port", "465");
        props.setProperty("mail.smtp.auth", "true");

// props.put("mail.smtp.host", "smtp.qq.com");
// props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
// props.put("mail.smtp.socketFactory.fallback", "false");
// props.put("mail.smtp.port", "465");
// props.put("mail.smtp.socketFactory.port", "465");
// props.put("mail.smtp.auth", "true");

你可能感兴趣的:(android下成功使用javamail发件QQ邮件、收件(SSL连接))