ERP项目JavaMail使用QQ邮箱,报错Could not connect to SMTP ,还有Authentication failed解决办法

报错Could not connect to SMTP host: smtp.qq.com, port: 465, response: -1

修改applicationContext_mail.xml文件

端口号改为:587;
在这里插入图片描述

报错Authentication failed; nested exception is javax.mail.AuthenticationFailedException

邮箱密码是开通pop3/smtp服务时所给的授权码,而不是你注册邮箱时的真实密码
改一下密码为授权码就可以了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个异常`com.sun.mail.util.MailConnectException`表示无法连接到指定的主机和端口。根据你提供的误信息,它显示你无法连接到主机`smtp.qq.com`的端口`456`。 可能的原因是: 1. 误的主机名或端口号:请确保你提供的主机名和端口号是正确的。在使用QQ邮箱SMTP服务器时,通常使用端口号`465`或`587`,而不是`456`。 2. 网络连接问题:检查你的网络连接是否正常,确保能够访问该主机和端口。有时候防火墙或网络配置会阻止连接。 3. 邮箱服务器设置问题:请确保你已正确设置了QQ邮箱SMTP服务器地址、端口号以及用户名和密码。你可以参考QQ邮箱提供的设置指南。 以下是一个示例代码片段,用于使用JavaMail发送电子邮件到QQ邮箱: ```java import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class SendEmail { public static void main(String[] args) { final String username = "your_email@qq.com"; final String password = "your_password"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.qq.com"); props.put("mail.smtp.port", "465"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(username)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient_email@example.com")); message.setSubject("Test Email"); message.setText("This is a test email."); Transport.send(message); System.out.println("Email sent successfully!"); } catch (MessagingException e) { e.printStackTrace(); } } } ``` 请将`your_email@qq.com`替换为你的QQ邮箱地址,`your_password`替换为你的QQ邮箱密码,以及`recipient_email@example.com`替换为收件人的邮箱地址。确保你的QQ邮箱已启用SMTP服务,并使用正确的SMTP服务器地址和端口号。 如果问题仍然存在,请检查你的网络连接和邮箱服务器设置,并确保网络能够正常连接到QQ邮箱SMTP服务器。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值