diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/auth/authentication/CatalogAuthenticationManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/auth/authentication/CatalogAuthenticationManager.java index 2f8f476f828..88b807edd3e 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/auth/authentication/CatalogAuthenticationManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/auth/authentication/CatalogAuthenticationManager.java @@ -133,7 +133,7 @@ public OpenCGAResult resetPassword(String userId) throws CatalogException { String mailHost = this.emailConfig.getHost(); String mailPort = this.emailConfig.getPort(); try { - MailUtils.sendResetPasswordMail(email, newPassword, mailUser, mailPassword, mailHost, mailPort); + MailUtils.sendResetPasswordMail(email, newPassword, mailUser, mailPassword, mailHost, mailPort, userId); result = userDBAdaptor.resetPassword(userId, email, newPassword); } catch (Exception e) { throw new CatalogException("Email could not be sent.", e); diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/common/MailUtils.java b/opencga-core/src/main/java/org/opencb/opencga/core/common/MailUtils.java index 19338531443..bf62bb7c09f 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/common/MailUtils.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/common/MailUtils.java @@ -16,6 +16,8 @@ package org.opencb.opencga.core.common; +import org.opencb.opencga.core.models.user.User; +import org.opencb.opencga.core.response.OpenCGAResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,20 +34,21 @@ public class MailUtils { private static final Logger logger = LoggerFactory.getLogger(MailUtils.class); - public static void sendResetPasswordMail(String to, String newPassword, final String mailUser, final String mailPassword, - String mailHost, String mailPort) throws Exception { - sendResetPasswordMail(to, newPassword, mailUser, mailPassword, - mailHost, mailPort, "true"); - } + public static void sendResetPasswordMail(String to, String newPassword, final String mailUser, final String mailPassword, - String mailHost, String mailPort, String ssl) throws Exception { + String mailHost, String mailPort, String userId) throws Exception { Properties props = new Properties(); - props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.starttls.enable", ssl); props.put("mail.smtp.host", mailHost); props.put("mail.smtp.port", mailPort); + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.ssl.enable", "true"); + props.put("mail.smtp.starttls.enable", "true"); + props.put("mail.smtp.starttls.required", "true"); + props.put("mail.smtp.ssl.protocols", "TLSv1.2"); + props.put("mail.smtp.ssl.checkserveridentity", "true"); + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { @@ -59,20 +62,31 @@ protected PasswordAuthentication getPasswordAuthentication() { message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); - message.setSubject("Your password has been reset"); - message.setText("Hello, \n" + - "You can now login using this new password:" + - "\n\n" + - newPassword + - "\n\n\n" + - "Please change it when you first login" + - "\n\n" + - "Best regards,\n\n" + - "Systems Genomics Laboratory" + - "\n"); + message.setSubject("XetaBase: Password Reset"); + message.setText(getEmailContent(userId,newPassword)); Transport.send(message); } + public static String getEmailContent(String userId, String temporaryPassword) { + StringBuilder sb = new StringBuilder(); + + sb.append("Hi ").append(userId).append(",\n\n"); + sb.append("We confirm that your password has been successfully reset.\n\n"); + sb.append("Please find your new login credentials below:\n\n"); + sb.append("User ID: ").append(userId).append("\n"); + sb.append("Temporary Password: ").append(temporaryPassword).append("\n\n"); + sb.append("For your security, we strongly recommend that you log in using the temporary password provided "); + sb.append("and promptly create a new password that is unique and known only to you. "); + sb.append("You can change your password by accessing \"Your Profile > Change Password\" in your User Profile.\n\n"); + sb.append("If you did not request a password reset, please contact our support team immediately at support@zettagenomics.com.\n\n"); + sb.append("Best regards,\n\n"); + sb.append("ZettaGenomics Support Team \n\n"); + + + + return sb.toString(); + } + public static void sendMail(String smtpServer, String to, String from, String subject, String body) throws Exception { Properties props = System.getProperties();