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

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