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

Java不停止发送电子邮件(JAvaMail Eclipse),java,eclipse,jakarta-mail,Java,Eclipse,Jakarta Mail,我正在从事一个Eclipse项目。我制作了一个注册激活链接,但是Java邮件发送的消息是无止境的 以下是我发送电子邮件的方法: public static Mailer sendMail(Mailer userActivation) { final String username = "harfrank2@gmail.com"; final String password = "";password for the email Propert

我正在从事一个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 userActivation object instead of returning sendMail(userActivation )

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 userActivation;    
}

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

您对这个as return语句有什么期望?返回sendMail(用户激活);将其设置为void方法并不返回任何内容,或者设置为布尔方法,在完成时返回true,或者在发送失败时返回false。对于此as return语句,您期望得到什么?返回sendMail(用户激活);让它成为一个void方法,不返回任何内容,或者是一个布尔方法,在完成时返回true,或者在发送失败时返回false。Let me have your guidence sir Let me have your guidence sir
//return userActivation object instead of returning sendMail(userActivation )

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 userActivation;    
}