使用Javamail操作QQ邮箱

问题记录 (JavaMail操作QQ邮箱)

参考:http://blog.csdn.net/u010695008/article/details/51701661

(学习中,遇到问题的记录)

try {
    Properties properties = new Properties();
    properties.setProperty("mail.host", "smtp.qq.com");
    properties.setProperty("mail.transport.protocol", "smtp");
    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.smtp.socketFactory.class",
                    "javax.net.ssl.SSLSocketFactory");
    properties.setProperty("mail.smtp.port", "465");
    properties.setProperty("mail.smtp.socketFactory.port", "465");
    Authenticator authenticator = new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("123456789",
                            "123456789邮箱开启smtp服务时腾讯给的授权码");
                }
            };
            Session session = Session.getDefaultInstance(properties,
                    authenticator);
            session.setDebug(true);
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("发件人邮箱"));
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(
                    "收件人邮箱"));
            message.setSubject("邮件主题部分");
            message.setContent(
                    "邮件内容部分",
                    "text/html;charset=UTF-8");
            Transport.send(message);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

你可能感兴趣的:(问题记录)