More improvements to the email sending functionality

merge-requests/7/head
prabathabey 9 years ago
parent 535c74a962
commit 0b31042aa2

@ -19,11 +19,14 @@ package org.wso2.carbon.device.mgt.core.email;
public final class EmailConstants {
public static final String DOMAIN = "domain-name";
public static final String USERNAME = "user-name";
public static final String DOWNLOAD_URL = "download-url";
public static final String ENCODED_SCHEME = "UTF-8";
public static final String PASSWORD = "password";
public static final String FIRST_NAME = "first-name";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String DOMAIN = "domain-name";
public static final String SERVER_BASE_URL_HTTPS = "base-url-https";
public static final String SERVER_BASE_URL_HTTP = "base-url-http";
public static final String DOWNLOAD_URL = "download-url";
}

@ -0,0 +1,65 @@
/*
* Copyright (c) 2016, 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.
*
*/
package org.wso2.carbon.device.mgt.core.email;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
import org.wso2.carbon.utils.NetworkUtils;
public class EmailUtil {
public static String getServerBaseHttpsUrl() {
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
ConfigurationContextService configContextService =
DeviceManagementDataHolder.getInstance().getConfigurationContextService();
int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
int httpsProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
mgtConsoleTransport);
if (httpsProxyPort > 0) {
port = httpsProxyPort;
}
return "https://" + hostName + ":" + port;
}
public static String getServerBaseHttpUrl() {
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
ConfigurationContextService configContextService =
DeviceManagementDataHolder.getInstance().getConfigurationContextService();
int port = CarbonUtils.getTransportPort(configContextService, "http");
int httpProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
"http");
if (httpProxyPort > 0) {
port = httpProxyPort;
}
return "http://" + hostName + ":" + port;
}
}

@ -18,7 +18,6 @@
package org.wso2.carbon.device.mgt.core.email.sender;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
import org.apache.axis2.AxisFault;
@ -28,7 +27,6 @@ import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.mail.MailConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@ -522,6 +522,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
params.put(EmailConstants.DOWNLOAD_URL,
new TypedValue<Class<?>, Object>(String.class,
emailConfig.getlBHostPortPrefix() + emailConfig.getEnrollmentContextPath()));
params.put(EmailConstants.SERVER_BASE_URL_HTTPS,
new TypedValue<Class<?>, Object>(String.class, EmailUtil.getServerBaseHttpsUrl()));
params.put(EmailConstants.SERVER_BASE_URL_HTTP,
new TypedValue<Class<?>, Object>(String.class, EmailUtil.getServerBaseHttpUrl()));
try {
EmailData data = contentProvider.getContent("user-enrollment", params);
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailCtx.getRecipients(), data);
@ -550,6 +554,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
new TypedValue<Class<?>, Object>(String.class, emailCtx.getProperty("password")));
params.put(EmailConstants.DOMAIN,
new TypedValue<Class<?>, Object>(String.class, emailCtx.getProperty("domain")));
params.put(EmailConstants.SERVER_BASE_URL_HTTPS,
new TypedValue<Class<?>, Object>(String.class, EmailUtil.getServerBaseHttpsUrl()));
params.put(EmailConstants.SERVER_BASE_URL_HTTP,
new TypedValue<Class<?>, Object>(String.class, EmailUtil.getServerBaseHttpUrl()));
try {
EmailData data = contentProvider.getContent("user-registration", params);
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailCtx.getRecipients(), data);

@ -44,7 +44,6 @@ import java.util.Locale;
@SuppressWarnings("unused")
public class RegistryBasedLicenseManager implements LicenseManager {
private Registry registry;
private GenericArtifactManager artifactManager;
private static final Log log = LogFactory.getLog(RegistryBasedLicenseManager.class);
@ -54,7 +53,6 @@ public class RegistryBasedLicenseManager implements LicenseManager {
throw new IllegalArgumentException("Registry instance retrieved is null. Hence, " +
"'Registry based license manager cannot be initialized'");
}
this.registry = registry;
try {
this.artifactManager = GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(registry);
} catch (LicenseManagementException e) {

@ -0,0 +1,55 @@
<EmailConfig>
<Subject>You have been invited to enroll your device in WSO2 EMM</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>WSO2 Enterprise Mobility Manager</title>
</head>
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
<div style="display: inline-block; line-height: 0px;">
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
</div>
</div>
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
Hi $first-name,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
You have been invited to enrol your device in WSO2 Enterprise Mobility Manager.
Click <a href="$download-url">here</a> to download the WSO2 EMM client application to begin device
enrolment.</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Should you need assistance, please contact your administrator.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Regards,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
WSO2 EMM Administrator
</p>
</div>
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="padding: 0px 20px 0px 0px;"><img
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>

@ -0,0 +1,65 @@
<EmailConfig>
<Subject>You have successfully been registered in WSO2 EMM</Subject>
<Body>
<![CDATA[
<html>
<head>
<title>WSO2 Enterprise Mobility Manager</title>
</head>
<body style="color: #666666; background-color:#cdcdcd; padding: 0px; margin: 0px;">
<div style="background-color:#cdcdcd; font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; padding: 20px 0px; margin: 0px;">
<div style="width: 86%; max-width: 650px; padding: 2%; background-color: #ffffff; margin: auto; border-radius: 14px;">
<div style="background-color: #49c8f5; line-height: 0px; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: 0px 10px 0px 0px;">
<div style="display: inline-block; line-height: 0px;">
<img src="http://b.content.wso2.com/sites/all/2015-june-theme/navigation/wso2-nav-logo.png"
alt="WSO2" style="margin: 0px 20px 0px 25px; width: 100%; max-width: 251px;"/>
</div>
</div>
<div style="background-color: #ffffff; line-height: 170%; color: #666666; padding: 20px 25px;">
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px 20px;">
Hi $first-name,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
You have been registered in WSO2 Enterprise Mobility Manager and invited to enrol your device.
Click <a href="$download-url">here</a> to download the WSO2 EMM client application to begin device
enrolment.</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Use following credentials to log in to WSO2 EMM client application.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
<b>Username:</b> $username
<br/>
<b>Password:</b> $password
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
Should you need assistance, please contact your administrator.
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 20px 0px 5px;">
Regards,
</p>
<p style="font-size: 1em; font-family: Arial, Helvetica; line-height: 170%; color: #666666; margin: 5px 0px;">
WSO2 EMM Administrator
</p>
</div>
<div style="background-color: #333333; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="padding: 0px 20px 0px 0px;"><img
src="http://b.content.wso2.com/newsletter/images/wso2-logo-cloud-footer.png" alt="WSO2"
style="margin: 15px 0px 15px 25px; width: 100%; max-width: 258px;"/></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
]]>
</Body>
</EmailConfig>

@ -1225,12 +1225,6 @@
<version>${version.commons.codec}</version>
</dependency>
<dependency>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
<version>${version.commons.io}</version>
</dependency>
<dependency>
<groupId>commons-lang.wso2</groupId>
<artifactId>commons-lang</artifactId>

Loading…
Cancel
Save