I am developing a web app a Spring based web app. I want know how I can notify administrator (site_mail) of new user registrations.
Asked
Active
Viewed 41 times
2 Answers
0
You have two options:
Use native command like:
Process p = new ProcessBuilder("command", "opt1", "opt2", "arg").start();
or use JavaMail

S. Kadakov
- 861
- 1
- 6
- 15
-
I didn't understand that process? – kati May 24 '16 at 13:49
-
Please see [javadoc](https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html) – S. Kadakov May 24 '16 at 13:53
-
but my question is about sending and receiving emails – kati May 24 '16 at 14:04
-
You can send email from within your app while registration process (by native command or JavaMail) and receive it normal way from your mail server. Or I'm missing something? – S. Kadakov May 24 '16 at 14:10
0
Use java mail to send e-mail after user creation
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);
}
}
see here: JavaMail API – Sending email

KlajdPaja
- 959
- 1
- 8
- 17
-
thanks for your reply, but this solution is for sending an email , in my case i want receive an email in my inbox with informations of registrataion when a user register to a site, sorry for my bad english – kati May 24 '16 at 13:48
-
Yes and that was my idea, in the method that registers a user to your site get the details of the user and send it by mail to your mail account – KlajdPaja May 24 '16 at 13:51
-
yes i try it but i want the email adresse that i put in my configuration file to be the receiver not the sender – kati May 24 '16 at 13:57
-
-
yes by inserting his email adresse in input field in the registration form – kati May 24 '16 at 14:01
-
In that case it can't be done..you cant send an email with every account you want in java code, every email provider has an unique account configuration, because the system administrator can decide to use a different authentication mode, different port for smtp etc etc.All you can do is redirect the user to his mail client and send the mail by himself. – KlajdPaja May 24 '16 at 14:05
-
but in contact us form we can contact the administrator of the site by sending to him a message – kati May 24 '16 at 14:09
-
Take a look here: [](http://stackoverflow.com/questions/10261995/finding-smtp-host-and-port-knowing-the-e-mail-address-using-java-api)...Still no answer exists for this – KlajdPaja May 24 '16 at 14:24
-
Well we can, how it's implemented?! My guess would be that there is another email configure be the dev team that sends your message and email to sites admin – KlajdPaja May 24 '16 at 17:50
-
but how the dev team receive the email from the user when he registred ?? i didn't know how i can implemented it in my web app – kati May 25 '16 at 11:13