我正在开发一个基于Spring的Web应用程序的Web应用程序。我想知道如何通知管理员(site_mail)新用户注册。
答案 0 :(得分:0)
您有两种选择:
使用本机命令,如:
Process p = new ProcessBuilder("command", "opt1", "opt2", "arg").start();
或使用JavaMail
答案 1 :(得分:0)
使用java邮件在用户创建后发送电子邮件
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);
}
}