Skip to content

Commit

Permalink
Mail method for sending new passwords, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
arc12012 committed Apr 22, 2017
1 parent 1f32fe9 commit 409d23f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/utilities/Mail.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,41 @@ protected PasswordAuthentication getPasswordAuthentication(){
mex.printStackTrace();
}
}

public void sendTemporaryPassword(String password) {
String subject = "Your temporary {Application name} password";
String messege = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
+ "<p>Your pasword has been reset. To login in, please use the password <b>"+password+"</b></p><br>"
+ "<p>You will be prompted to set a new password. If you didn't initiate this, sorry. Someone's probably messing with you.</p>"
+ "</body>"
+ "<footer style='text-align: center;'><font size='1'>To change notification settings, please visit your <a href='"+profileLink+"'>profile settings page</a></font></footer>"
+ "</html>";
Properties properties = System.getProperties();
properties = setProp(sender, client.getEmail());
Session session = Session.getInstance(properties, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(sender, password);
}
});

try {
Address address = new InternetAddress(client.getEmail());
MimeMessage message = new MimeMessage(session);
message.setFrom(address);
message.addRecipient(Message.RecipientType.TO, address);
message.setSubject(subject);
message.setText(messege,"utf-8","html");
message.saveChanges();
Transport.send(message);
System.out.println("Sent message successfully....");

} catch (Exception mex) {
mex.printStackTrace();
}
}

private Properties setProp(String email, String targetEmail) {
Properties props = null;
try {
Expand Down

0 comments on commit 409d23f

Please sign in to comment.