gpt4 book ai didi

Java 不停止发送电子邮件 (JAvaMail Eclipse)

转载 作者:行者123 更新时间:2023-12-01 19:50:45 27 4
gpt4 key购买 nike

我正在开发一个 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);

将无限地调用该方法。删除递归调用并返回正确的邮件程序。

关于Java 不停止发送电子邮件 (JAvaMail Eclipse),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51377404/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com