在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  HTML/ Java發(fā)送郵件老是報這錯,怎么解決?

Java發(fā)送郵件老是報這錯,怎么解決?

javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl)

Properties prop = new Properties();

        prop.setProperty("mail.transport.protocol", "smtp"); // 設(shè)置郵件發(fā)送協(xié)議
        prop.setProperty("mail.host", "smtp.qq.com"); // 郵件服務(wù)器地址

        //prop.setProperty("mail.smtps.ssl.enable", "true"); // 郵件ssl驗(yàn)證
        prop.setProperty("mail.smtp.auth", "true"); // 郵件服務(wù)身份驗(yàn)證
        //prop.setProperty("mail.smtp.localhost", "127.0.0.1");


        Session session = Session.getDefaultInstance(prop);

        // 收件人電子郵箱
        String to = "xxxxx@qq.com";

        // 發(fā)件人電子郵箱
        String from = "xxxx@qq.com";

        try{
            // 創(chuàng)建默認(rèn)的 MimeMessage 對象
            MimeMessage message = new MimeMessage(session);

            // Set From: 頭部頭字段
            message.setFrom(new InternetAddress(from));

            // Set To: 頭部頭字段
            message.addRecipient(Message.RecipientType.TO,
                    new InternetAddress(to));

            // Set Subject: 頭部頭字段
            message.setSubject("This is the Subject Line!");

            // 設(shè)置消息體
            message.setText("This is actual message");

            // 根據(jù) Session 獲取郵件傳輸對象
            Transport transport = session.getTransport();
            transport.connect("xxx@qq.com","xxxxx");
            // 發(fā)送消息
            transport.send(message);
            System.out.println("Sent message successfully....");
        }catch (MessagingException mex) {
            mex.printStackTrace();
        }
回答
編輯回答
涼薄

服務(wù)器要求加密,你卻注釋掉了

 //prop.setProperty("mail.smtps.ssl.enable", "true"); // 郵件ssl驗(yàn)證
2018年3月31日 23:24