// 设置邮件服务器端口
        props.setProperty("mail.smtp.socketFactory.port", "587");
        //服务器
        props.put("smtp.163.com", "587");

        // SSL加密
        MailSSLSocketFactory sf = null;
        try {
            sf = new MailSSLSocketFactory();
            // 设置信任所有的主机 - 解决Linux无法发送邮箱的问题
            sf.setTrustAllHosts(true);
            props.put("mail.smtp.ssl.enable", "true");
            props.put("mail.smtp.ssl.socketFactory", sf);
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        }

Logo

一站式 AI 云服务平台

更多推荐