关于javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 25;

在这里插入图片描述
在这里插入图片描述
记得开阿里云的465端口

最近准备将一个项目发布到阿里云,在本地所有的功能都能够实现的很好,但是一到阿里云

错误报告内容:Could not connect to SMTP host: smtp.163.com, port: 25
翻译起来就是:不能连接到smtp.163.com,因为25号端口的原因。

在这里插入图片描述在这里插入图片描述也就是说,可以修改为:

public static void main(String[] args) throws Exception {
        Properties prop = new Properties();
        //协议
        prop.setProperty("mail.transport.protocol", "smtp");
        //服务器
        prop.setProperty("mail.smtp.host", "smtp.exmail.qq.com");
        //端口
        prop.setProperty("mail.smtp.port", "465");
        //使用smtp身份验证
        prop.setProperty("mail.smtp.auth", "true");
 
        //获取Session对象
        Session s = Session.getDefaultInstance(prop,new Authenticator() {
            //此访求返回用户和密码的对象
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication pa = new PasswordAuthentication("***", "********");
                return pa;
            }
        });
        //设置session的调试模式,发布时取消
        s.setDebug(true);
        MimeMessage mimeMessage = new MimeMessage(s);
        try {
            mimeMessage.setFrom(new InternetAddress("***@163.com"));
            mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("********@**.com"));
            //设置主题
            mimeMessage.setSubject("账户密码重置");
            mimeMessage.setSentDate(new Date());
            //设置内容
            mimeMessage.setText("您使用了密码重置功能");
            mimeMessage.saveChanges();
            //发送
            Transport.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
        
    }
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值