I am working on an Eclipse project. I was making a registration activation link but yet the Java mail is sending the message endless
Here is my method to send Email:
public static Mailer sendMail(Mailer userActivation) {
final String username = "[email protected]";
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("[email protected]"));
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);
Will call the method infinitely. remove the recursion call and return proper mailer.