星涯无痕 2016-01-26 07:29 采纳率: 0%
浏览 2259

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条回答

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图