Reuse email implementation

fixes http://roadmap.entgra.net/issues/9939
master
osh 2 years ago
parent 24064b650b
commit f89e71d4bf

@ -136,6 +136,7 @@ public final class DeviceManagementConstants {
public static final String POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier";
public static final String USER_WELCOME_TEMPLATE = "user-welcome";
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
public static final String ENROLLMENT_GUIDE_TEMPLATE = "enrollment-guide";
}
public static final class OperationAttributes {

@ -1583,38 +1583,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException {
String to = "oshani@entgra.io";
String from = "oshsilva1996@gmail.com";
String host = "smtp.gmail.com";
Properties properties = System.getProperties();
// Setup mail server
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true");
Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("oshsilva1996@gmail.com", "layzvxhcxlwzkgwf");
}
});
// Used to debug SMTP issues
session.setDebug(true);
Properties props = new Properties();
props.setProperty("mail-subject", "[Enrollment Guide Triggered] (#" + ++count + ")");
props.setProperty("enrollment-guide", enrolmentGuide);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("[Enrollment Guide Triggered] (#" + ++count + ")");
message.setText(enrolmentGuide);
Transport.send(message);
} catch (MessagingException e) {
String msg = "Error occurred while sending message to support dev group";
log.error(msg, e);
EmailMetaInfo metaInfo = new EmailMetaInfo("support-dev-group@entgra.io", props);
sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.ENROLLMENT_GUIDE_TEMPLATE, metaInfo);
} catch (ConfigurationManagementException e) {
String msg = "Error occurred while sending the mail.";
log.error(msg);
throw new DeviceManagementException(msg, e);
}
}

@ -0,0 +1,34 @@
#*
Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
you may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*#
<EmailConfig>
<Subject>$mail-subject</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>Enrollment Questions and Answers</title>
</head>
<body>
<div>
$enrollment-guide
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>
Loading…
Cancel
Save