我已经发送了激活链接,并且它已经可以工作了。但是我不知道如何在下面的代码中重新发送链接;
private void sendActivationEmail(User user, String baseUrl) throws SignUpException {
String message = "";
String p = getSignupToken(user);
UserNotificationEmail userNotificationEmail = new UserNotificationEmail();
userNotificationEmail.setLoginName(user.getLoginName());
userNotificationEmail.setConfParameter(p);
userNotificationEmail.setIsActive("T");
userNotificationEmail.setSentDate(new Date());
userNotificationEmailRepository.save(userNotificationEmail);
String confirmationBaseUrl = env.getProperty("confirmation.email.baseurl", baseUrl);
try {
message = emailTemplateLoader.getEmailBody(user.getName(),
confirmationBaseUrl + "/user/confirmation?u=" + user.getLoginName() + "&p=" + p);
} catch (Exception e) {
logger.debug("Template exception. {}", e.getMessage());
throw new SignUpException("Error creating email body.");
}
logger.info("Sign up message: {}", message);
try {
emailSender.sendEmail(user.getEmail(), "Welcome ", message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
和我的重发方法
public void resendActivationEmail(String loginName, String baseUrl) throws SignUpException {
// find user from database using loginName
// send activation email using sendActivationEmail method
User user = userRepository.findByLoginName(loginName);
sendActivationEmail(user, baseUrl);
}