2 u010125873 u010125873 于 2016.01.26 15:29 提问

java 用QQ邮箱发邮件问题

代码如下:

private static final String account = "xxx@qq.com";
    private static final String password = "xxx";
    private static final String host = "smtp.qq.com";
    //  private static final String account = "xxx@163.com";
//  private static final String password = "xxx";
//  private static final String host = "smtp.163.com";
 public static void main(String[] args) {
        String content = "dfaferdfgfd";
        Session session = getSession();  
            MimeMessage message = new MimeMessage(session);  
            try {  
                message.setSubject("找回您的帐户与密码");  
                message.setSentDate(new Date());  
                message.setFrom(new InternetAddress(account));  
                message.setRecipient(RecipientType.TO, new InternetAddress(to));  
                message.setContent(content,"text/html;charset=utf-8");  
                // 发送邮件  
                System.out.println("sendResetPasswordEmail:邮件发送-->");
                Transport.send(message);  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
    }
    public static Session getSession() {  
        Security.getProviders();       
        Properties props = new Properties();  
        props.setProperty("mail.transport.protocol", "smtp");  
        props.setProperty("mail.smtp.host", host);  
        props.setProperty("mail.smtp.port", "25");  
        props.setProperty("mail.smtp.auth", "true"); 
//          props.setProperty("mail.smtp.ssl.enable", "false"); 
//          props.setProperty("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); 
//          props.setProperty("mail.smtp.port","465");
//          props.setProperty("mail.smtp.socketFactory.port","465");
        Session session = Session.getInstance(props, new Authenticator() {  
            @Override  
            protected PasswordAuthentication getPasswordAuthentication() {  
                return new PasswordAuthentication(account, password);  
            }  

        });  
        session.setDebug(true);
        return session;  
    } 

使用163邮箱发送邮件正常,用QQ邮箱发送就报错了。报错如图,邮箱帐号密码是正确的
图片说明

2个回答

rui888
rui888   Ds   Rxr 2016.01.26 15:39
sun2015_07_24
sun2015_07_24   2016.01.27 08:45
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!