List of usage examples for javax.mail MessagingException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.mxhero.engine.plugin.attachmentlink.alcommand.internal.domain.Message.java
public boolean hasAttachments() { boolean hasAttach = false; try {//from w ww. j a v a 2s . c om MimeMessage message = getMail().getMessage(); hasAttach = hasAttach(message); } catch (MessagingException e) { log.error("Could not verify if the email has attachments. EmailId: " + getMessagePlatformId() + " - " + e.getClass().getName() + " - " + e.getMessage()); throw new RuntimeException("Could not read mime message"); } catch (IOException e) { log.error("Could not verify if the email has attachments. EmailId: " + getMessagePlatformId() + " - " + e.getClass().getName() + " - " + e.getMessage()); throw new RuntimeException("Could not read mime message"); } return hasAttach; }
From source file:org.nuxeo.ecm.platform.ec.notification.NotificationEventListener.java
public void sendNotification(Event event, DocumentEventContext ctx) { String eventId = event.getName(); log.debug("Received a message for notification sender with eventId : " + eventId); Map<String, Serializable> eventInfo = ctx.getProperties(); String userDest = (String) eventInfo.get(NotificationConstants.DESTINATION_KEY); NotificationImpl notif = (NotificationImpl) eventInfo.get(NotificationConstants.NOTIFICATION_KEY); // send email NuxeoPrincipal recepient = NotificationServiceHelper.getUsersService().getPrincipal(userDest); if (recepient == null) { log.error("Couldn't find user: " + userDest + " to send her a mail."); return;/*from w ww .ja v a 2 s .co m*/ } String email = recepient.getEmail(); if (email == null || "".equals(email)) { log.error("No email found for user: " + userDest); return; } String subjectTemplate = notif.getSubjectTemplate(); String mailTemplate = null; // mail template can be dynamically computed from a MVEL expression if (notif.getTemplateExpr() != null) { try { mailTemplate = emailHelper.evaluateMvelExpresssion(notif.getTemplateExpr(), eventInfo); } catch (PropertyAccessException pae) { if (log.isDebugEnabled()) { log.debug("Cannot evaluate mail template expression '" + notif.getTemplateExpr() + "' in that context " + eventInfo, pae); } } } // if there is no mailTemplate evaluated, use the defined one if (StringUtils.isEmpty(mailTemplate)) { mailTemplate = notif.getTemplate(); } log.debug("email: " + email); log.debug("mail template: " + mailTemplate); log.debug("subject template: " + subjectTemplate); Map<String, Object> mail = new HashMap<String, Object>(); mail.put("mail.to", email); String authorUsername = (String) eventInfo.get(NotificationConstants.AUTHOR_KEY); if (authorUsername != null) { NuxeoPrincipal author = NotificationServiceHelper.getUsersService().getPrincipal(authorUsername); mail.put(NotificationConstants.PRINCIPAL_AUTHOR_KEY, author); } mail.put(NotificationConstants.DOCUMENT_KEY, ctx.getSourceDocument()); String subject = notif.getSubject() == null ? NotificationConstants.NOTIFICATION_KEY : notif.getSubject(); subject = notificationService.getEMailSubjectPrefix() + subject; mail.put("subject", subject); mail.put("template", mailTemplate); mail.put("subjectTemplate", subjectTemplate); // Transferring all data from event to email for (String key : eventInfo.keySet()) { mail.put(key, eventInfo.get(key) == null ? "" : eventInfo.get(key)); log.debug("Mail prop: " + key); } mail.put(NotificationConstants.EVENT_ID_KEY, eventId); try { emailHelper.sendmail(mail); } catch (MessagingException e) { String cause = ""; if ((e instanceof SendFailedException) && (e.getCause() instanceof SendFailedException)) { cause = " - Cause: " + e.getCause().getMessage(); } log.warn("Failed to send notification email to '" + email + "': " + e.getClass().getName() + ": " + e.getMessage() + cause); } }
From source file:org.nuxeo.ecm.platform.notification.async.AdvancedNotificationEventListener.java
public void sendNotification(Event event, DocumentEventContext ctx) throws ClientException { String eventId = event.getName(); log.debug("Received a message for notification sender with eventId : " + eventId); Map<String, Serializable> eventInfo = ctx.getProperties(); String userDest = (String) eventInfo.get(NotificationConstants.DESTINATION_KEY); NotificationImpl notif = (NotificationImpl) eventInfo.get(NotificationConstants.NOTIFICATION_KEY); // send email NuxeoPrincipal recepient = NotificationServiceHelper.getUsersService().getPrincipal(userDest); if (recepient == null) { log.error("Couldn't find user: " + userDest + " to send her a mail."); return;/*from w ww .ja va2 s. c om*/ } // XXX hack, principals have only one model DataModel model = recepient.getModel().getDataModels().values().iterator().next(); String email = (String) model.getData("email"); if (email == null || "".equals(email)) { log.error("No email found for user: " + userDest); return; } String subjectTemplate = notif.getSubjectTemplate(); String mailTemplate = null; // mail template can be dynamically computed from a MVEL expression if (notif.getTemplateExpr() != null) { mailTemplate = emailHelper.evaluateMvelExpresssion(notif.getTemplateExpr(), eventInfo); } // if there is no mailTemplate evaluated, use the defined one if (StringUtils.isEmpty(mailTemplate)) { mailTemplate = notif.getTemplate(); } log.debug("email: " + email); log.debug("mail template: " + mailTemplate); log.debug("subject template: " + subjectTemplate); Map<String, Object> mail = new HashMap<String, Object>(); mail.put("mail.to", email); String authorUsername = (String) eventInfo.get(NotificationConstants.AUTHOR_KEY); if (authorUsername != null) { NuxeoPrincipal author = NotificationServiceHelper.getUsersService().getPrincipal(authorUsername); mail.put(NotificationConstants.PRINCIPAL_AUTHOR_KEY, author); } mail.put(NotificationConstants.DOCUMENT_KEY, ctx.getSourceDocument()); String subject = notif.getSubject() == null ? NotificationConstants.NOTIFICATION_KEY : notif.getSubject(); subject = notificationService.getEMailSubjectPrefix() + subject; mail.put("subject", subject); mail.put("template", mailTemplate); mail.put("subjectTemplate", subjectTemplate); // Transferring all data from event to email for (String key : eventInfo.keySet()) { mail.put(key, eventInfo.get(key) == null ? "" : eventInfo.get(key)); log.debug("Mail prop: " + key); } mail.put(NotificationConstants.EVENT_ID_KEY, eventId); try { emailHelper.sendmail(mail); } catch (MessagingException e) { log.warn("Failed to send notification email to '" + email + "': " + e.getClass().getName() + ": " + e.getMessage()); } catch (Exception e) { throw new ClientException("Failed to send notification email ", e); } }
From source file:trendplot.TrendPlot.java
private void testEmail() { Properties fMailServerConfig; fMailServerConfig = new Properties(); fMailServerConfig.setProperty("mail.host", "ldas-cit.ligo.caltech.edu"); fMailServerConfig.setProperty("mail.smtp.host", "ldas-cit.ligo.caltech.edu"); Session session = Session.getDefaultInstance(fMailServerConfig, null); MimeMessage message = new MimeMessage(session); try {/*from w ww. ja v a 2 s.co m*/ //the "from" address may be set in code, or set in the //config file under "mail.from" ; here, the latter style is used message.setFrom(new InternetAddress("areeda@ligo.caltech.edu")); String email = "joe@areeda.com"; message.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); String msg = "<h3>this is a test</h3>"; message.setSubject("Test email"); message.setText(msg, "utf-8", "html"); Transport.send(message); System.out.format("Email sent to %1$s\n", email); } catch (MessagingException ex) { System.err.format("Exception: %1$s: %2$s", ex.getClass().getSimpleName(), ex.getLocalizedMessage()); } }