added email notification
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@126250 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
26aac386fe
commit
0a194defa5
40
pom.xml
40
pom.xml
|
@ -29,6 +29,17 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.distribution</groupId>
|
||||||
|
<artifactId>maven-portal-bom</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
|
@ -42,6 +53,11 @@
|
||||||
<version>2.0</version>
|
<version>2.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.mail</groupId>
|
||||||
|
<artifactId>javax.mail</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.liferay.portal</groupId>
|
<groupId>com.liferay.portal</groupId>
|
||||||
<artifactId>portal-service</artifactId>
|
<artifactId>portal-service</artifactId>
|
||||||
|
@ -55,26 +71,24 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.liferay.portal</groupId>
|
<groupId>com.liferay.portal</groupId>
|
||||||
<artifactId>util-bridges</artifactId>
|
<artifactId>util-bridges</artifactId>
|
||||||
<version>${liferay.version}</version>
|
<version>${liferay.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.liferay.portal</groupId>
|
<groupId>com.liferay.portal</groupId>
|
||||||
<artifactId>util-taglib</artifactId>
|
<artifactId>util-taglib</artifactId>
|
||||||
<version>${liferay.version}</version>
|
<version>${liferay.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
<version>1.6.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.6.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
package org.gcube.common.portal.mailing;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.mail.Address;
|
||||||
|
import javax.mail.Message;
|
||||||
|
import javax.mail.Session;
|
||||||
|
import javax.mail.Transport;
|
||||||
|
import javax.mail.internet.InternetAddress;
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
|
|
||||||
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Massimiliano Assante
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EmailNotification {
|
||||||
|
private static Logger _log = LoggerFactory.getLogger(EmailNotification.class);
|
||||||
|
/**
|
||||||
|
* The sender of the email
|
||||||
|
*/
|
||||||
|
private static final String EMAIL_SENDER = PortalContext.getConfiguration().getSenderEmail();
|
||||||
|
private static final String PORTAL_NAME = PortalContext.getConfiguration().getGatewayName();
|
||||||
|
/**
|
||||||
|
* The recipients of the email
|
||||||
|
*/
|
||||||
|
private String emailrecipients[];
|
||||||
|
/**
|
||||||
|
* Email's subject
|
||||||
|
*/
|
||||||
|
private String emailSubject;
|
||||||
|
/**
|
||||||
|
* Email's body message
|
||||||
|
*/
|
||||||
|
private StringBuffer emailBody;
|
||||||
|
/**
|
||||||
|
* @param recipients
|
||||||
|
* @param subject
|
||||||
|
* @param body
|
||||||
|
*/
|
||||||
|
public EmailNotification(String recipients[], String subject, String body) {
|
||||||
|
emailrecipients = recipients;
|
||||||
|
emailSubject = subject;
|
||||||
|
|
||||||
|
emailBody = new StringBuffer(body);
|
||||||
|
emailBody.append("<p>")
|
||||||
|
.append("<p><div style=\"color:#999999; font-size:10px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif; padding-top:15px;\">")
|
||||||
|
.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain ")
|
||||||
|
.append("information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message.")
|
||||||
|
.append("If you have received this communication in error, please notify the <sender> and destroy and delete any copies you may have received.")
|
||||||
|
.append("</div></p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendEmail() {
|
||||||
|
Properties props = System.getProperties();
|
||||||
|
String mailServiceHost = "localhost";
|
||||||
|
props.put("mail.smtp.host", mailServiceHost);
|
||||||
|
String mailServicePort = "25";
|
||||||
|
props.put("mail.smtp.port", mailServicePort);
|
||||||
|
Session session = Session.getDefaultInstance(props, null);
|
||||||
|
session.setDebug(true);
|
||||||
|
Message mimeMessage = new MimeMessage(session);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// EMAIL SENDER
|
||||||
|
Address from = new InternetAddress(EMAIL_SENDER, PORTAL_NAME);
|
||||||
|
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
|
||||||
|
mimeMessage.setFrom(from);
|
||||||
|
|
||||||
|
// EMAIL RECIPIENTS
|
||||||
|
for (int i=0; i<emailrecipients.length; i++) {
|
||||||
|
Address address = new InternetAddress(emailrecipients[i]);
|
||||||
|
mimeMessage.addRecipient(Message.RecipientType.TO, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
mimeMessage.setSubject(emailSubject);
|
||||||
|
mimeMessage.setContent(emailBody.toString(), "text/html; charset=UTF-8");
|
||||||
|
mimeMessage.setSentDate(new Date());
|
||||||
|
Transport.send(mimeMessage);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
_log.error("Failed to send the email message.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue