-4

我正在开发一个基于 Spring 的网络应用程序的网络应用程序。我想知道如何将新用户注册通知管理员 (site_mail)。

4

2 回答 2

0

创建用户后使用java mail发送邮件

final String username = "admin@gmail.com";
        final String password = "password";

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

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("from-email@gmail.com"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("to-email@gmail.com"));
            message.setSubject("Testing Subject");
            message.setText("New user created");
            Transport.send(message);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }

请参阅此处:JavaMail API – 发送电子邮件

于 2016-05-24T13:30:17.307 回答
0

你有两个选择:

使用本机命令,例如:

Process p = new ProcessBuilder("command", "opt1", "opt2", "arg").start();

或使用 JavaMail

于 2016-05-24T12:14:56.527 回答