improved centralized messaging

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@128320 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-04-26 15:13:45 +00:00
parent da570dc81c
commit 1f58c4f1e1
1 changed files with 3 additions and 14 deletions

View File

@ -85,7 +85,7 @@ public class EmailNotification {
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("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>");
}
@ -105,18 +105,14 @@ public class EmailNotification {
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Message mimeMessage = new MimeMessage(session);
Transport t = null;
try {
t = session.getTransport("smtp");;
// EMAIL SENDER
String emailSender = PortalContext.getConfiguration().getSenderEmail(request);
String siteName = PortalContext.getConfiguration().getGatewayName(request);
Address from = new InternetAddress(emailSender, siteName);
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
mimeMessage.setFrom(from);
t.connect();
// EMAIL RECIPIENTS
for (int i=0; i<emailrecipients.length; i++) {
Address address = new InternetAddress(emailrecipients[i]);
@ -131,23 +127,16 @@ public class EmailNotification {
mimeMessage.setContent(emailBody.toString(), "text/html; charset=UTF-8");
mimeMessage.setSentDate(new Date());
Address[] addresses = mimeMessage.getAllRecipients();
try {
t.sendMessage(mimeMessage, addresses);
Transport.send(mimeMessage);
}
catch (com.sun.mail.smtp.SMTPSendFailedException ex) {
_log.error("Error while trying to send emails");
ex.printStackTrace();
}
t.close();
} catch (Exception e) {
e.printStackTrace();
_log.error("Failed to send the email message.", e);
try {
t.close();
} catch (MessagingException e1) {
e1.printStackTrace();
}
}
}