Reuse email implementation

fixes http://roadmap.entgra.net/issues/9939
pull/73/head
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 POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier";
public static final String USER_WELCOME_TEMPLATE = "user-welcome"; public static final String USER_WELCOME_TEMPLATE = "user-welcome";
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation"; public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
public static final String ENROLLMENT_GUIDE_TEMPLATE = "enrollment-guide";
} }
public static final class OperationAttributes { public static final class OperationAttributes {

@ -1583,38 +1583,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException { public void sendEnrolmentGuide(String enrolmentGuide) throws DeviceManagementException {
String to = "oshani@entgra.io"; Properties props = new Properties();
String from = "oshsilva1996@gmail.com"; props.setProperty("mail-subject", "[Enrollment Guide Triggered] (#" + ++count + ")");
String host = "smtp.gmail.com"; props.setProperty("enrollment-guide", enrolmentGuide);
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);
try { try {
MimeMessage message = new MimeMessage(session); EmailMetaInfo metaInfo = new EmailMetaInfo("support-dev-group@entgra.io", props);
message.setFrom(new InternetAddress(from)); sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.ENROLLMENT_GUIDE_TEMPLATE, metaInfo);
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("[Enrollment Guide Triggered] (#" + ++count + ")"); } catch (ConfigurationManagementException e) {
message.setText(enrolmentGuide); String msg = "Error occurred while sending the mail.";
Transport.send(message); log.error(msg);
} catch (MessagingException e) {
String msg = "Error occurred while sending message to support dev group";
log.error(msg, e);
throw new DeviceManagementException(msg, e); 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