java - Java 不停止发送电子邮件 (JAvaMail Eclipse)
问题描述
我正在开发一个 Eclipse 项目。我正在制作注册激活链接,但 Java 邮件不断发送消息
这是我发送电子邮件的方法:
public static Mailer sendMail(Mailer userActivation) {
final String username = "harfrank2@gmail.com";
final String password = "";password for the email
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
String userEmail = userActivation.getActvEmail();
String ActMessage = userActivation.getActLink();
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("harfrank2@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(userEmail));
message.setSubject("E-Dealing Activation Link");
message.setText("Dear "+userEmail
+ "\n\n You have a registered"
+ ", Please Click the link bellow to activate your acoount"
+ "\n Product "+ActMessage
);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
return sendMail(userActivation);
}
解决方案
return sendMail(userActivation);
将无限调用该方法。删除递归调用并返回正确的邮件。
推荐阅读
- typescript - TypeScript 检查字符串匹配类型
- python - django async 如果其他使用线程或 sync_to_async
- node.js - 如何在查询的基础上执行命令 discord.js?
- postgresql - 无法将对象推入空数组
- xml - 传递 SOAP req:传递 ItemNo String 但它无法找到在 NAV 2018 中作为 Web 服务公开的 Codeunit
- dart - 使用符号传递班级成员的姓名?
- mongodb - 如何在 mongo/wiredtiger mongo 4.4 版中获取碎片统计信息
- php - PHP文件处理读写
- python-3.x - 使用 sklearn 中的 linear_model 感知器模块来分离点
- google-apps-script - 为什么 Google Apps 脚本中的 getBlob() 没有获取最新版本的文档?