From f89e71d4bf2a730f181a179c571239507b0c3299 Mon Sep 17 00:00:00 2001 From: osh Date: Mon, 27 Mar 2023 19:46:51 +0530 Subject: [PATCH] Reuse email implementation fixes http://roadmap.entgra.net/issues/9939 --- .../mgt/core/DeviceManagementConstants.java | 1 + .../DeviceManagementProviderServiceImpl.java | 39 +++++-------------- .../email/templates/enrollment-guide.vm | 34 ++++++++++++++++ 3 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index 9ba76f99fb..0d45a2efc1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -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 { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index ded3d067fe..2b5c0dffae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -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); } } diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm new file mode 100644 index 0000000000..f4f16cc8d7 --- /dev/null +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/enrollment-guide.vm @@ -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. +*# + + $mail-subject + + + + Enrollment Questions and Answers + + +
+ $enrollment-guide +
+ + + ]]> + +