Could not connect to SMTP host: smtp.qq.com, port: 465

Could not connect to SMTP host: smtp.qq.com, port: 465

  • 关于使用java发送QQ邮件,出现465端口不能连接的问题
    • 解决

关于使用java发送QQ邮件,出现465端口不能连接的问题

//创建一个配置文件并保存
Properties properties = new Properties();
properties.setProperty("mail.host","smtp.qq.com");
properties.setProperty("mail.transport.protocol","smtp");
properties.setProperty("mail.smtp.auth","true");

//QQ存在一个特性设置SSL加密
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.ssl.socketFactory", sf);

这样写会出现连接不到465端口的错误

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

解决

将下面SSL加密部分代码注释即可

//创建一个配置文件并保存
Properties properties = new Properties();
properties.setProperty("mail.host","smtp.qq.com");
properties.setProperty("mail.transport.protocol","smtp");
properties.setProperty("mail.smtp.auth","true");

//QQ存在一个特性设置SSL加密
//MailSSLSocketFactory sf = new MailSSLSocketFactory();
//sf.setTrustAllHosts(true);
//properties.put("mail.smtp.ssl.enable", "true");
//properties.put("mail.smtp.ssl.socketFactory", sf);

你可能感兴趣的:(javamail)