
最近,我将向腾讯云发布一个项目. 所有本地功能都可以很好地实现. 但是,腾讯云出现了一个问题:
错误报告内容: 无法连接到SMTP主机: smtp.163.comqq smtp 25,端口: 25
翻译意味着: 由于端口25而无法连接到smtp.163.com.

这是因为出于安全考虑,腾讯云(阿里云)将禁用端口25.
这是腾讯云的后端:


解决方案是:
解除阻塞端口25(不推荐);使用其他端口(建议使用端口465).
以下是163邮箱的屏幕截图:

换句话说,可以将其修改为:

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();
}
}
在上述腾讯云的后端,据说还有另一种解决方案(推荐): 腾讯企业邮箱.
换句话说: 我们可以使用域名作为邮箱的后缀!
例如: 我的域名是lvchademiao.com,因此我可以使用message.lvchademiao.com作为邮箱发送电子邮件!
这是一个很好的操作,并且此功能是免费的!
附加地址: 腾讯公司邮箱.

下一步是一堆注册和其他步骤. 注册后,我申请了电子邮件. lvchademiao.com.
接下来,另一个问题出现了:

错误报告的内容: 535错误: ÇëʹÓÃÊÚȨµµÂ¼(一堆乱码)

解决方案都说没有使用授权码!

兄弟qq smtp 25,如果我使用邮箱的SMTP功能,可以使用授权码! !
最后一个关键点是: 当发件人的帐户是个人免费邮箱时,不能使用@和以下名称添加用户名,但是,如果发件人的帐户是公司邮箱,则必须使用@和添加发件人的帐户. 以下.
个人免费电子邮件可以如下: ms.setAuth(“ 111111111”,“ password1”);
但是公司电子邮件必须是这样的: ms.setAuth(“ 111111111@xxx.com”,“ password1”);
换句话说:
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");
//使用SSL,企业邮箱必需!
//开启安全协议,如果出错显示类不存在,就更新mail的jar包
MailSSLSocketFactory sf = null;
try {
sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
} catch (GeneralSecurityException e1) {
e1.printStackTrace();
}
prop.put("mail.smtp.ssl.enable", "true");
prop.put("mail.smtp.ssl.socketFactory", sf);
//获取Session对象
Session s = Session.getDefaultInstance(prop,new Authenticator() {
//此访求返回用户和密码的对象
@Override
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication pa = new PasswordAuthentication("message@lvchademiao.com", "********");
return pa;
}
});
//设置session的调试模式,发布时取消
s.setDebug(true);
MimeMessage mimeMessage = new MimeMessage(s);
try {
mimeMessage.setFrom(new InternetAddress("message@lvchademiao.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();
}
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-288758-1.html
不惜一战
特工在我国从事反华活动吗