List of usage examples for javax.mail MessagingException getMessage
public String getMessage()
From source file:com.cloudbees.demo.beesshop.web.ProductController.java
@RequestMapping(value = "/product/{id}/mail", method = RequestMethod.POST) public String sendEmail(@PathVariable long id, @RequestParam("recipientEmail") String recipientEmail, HttpServletRequest request, RedirectAttributes redirectAttributes) { Product product = productRepository.get(id); if (product == null) { throw new ProductNotFoundException(id); }// w w w . j av a 2s .co m try { String productPageUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/product/" + id; mailService.sendProductEmail(product, recipientEmail, productPageUrl); redirectAttributes.addFlashAttribute("mailSuccessMessage", "Email sent!"); } catch (MessagingException e) { redirectAttributes.addFlashAttribute("mailFailureMessage", "Failure sending email: " + e.getMessage()); logger.warn("Failure sending message to " + recipientEmail, e); } return "redirect:/product/" + product.getId(); }
From source file:org.apache.axis2.transport.mail.server.SMTPWorker.java
public void run() { try {/*from w ww .ja v a 2s.co m*/ // do initial transmission. initializeClient(); // analyze all the inputs from client and work accordingly. while (runThread) { String input = null; // get client input input = reader.readLine(); String retString = processInput(input); if (Constants.COMMAND_EXIT.equals(retString)) { exitWorker(); } else { if (retString != null) { send(retString); // Send the reply } if ((mail != null) && transmitionEnd) { exitWorker(); } } } for (int idx = 0; idx < receivers.size(); idx++) { try { MailSorter mSort = null; if (actAsMailet) { mSort = new MailSorter(this.st, this.configurationContext); } else { mSort = new MailSorter(this.st, null); } mSort.sort((String) receivers.get(idx), new MimeMessage(mail)); } catch (MessagingException e1) { log.info(e1.getMessage()); // e1.printStackTrace(); } } // } catch (IOException e) { log.info("ERROR: CLIENT CLOSED THE SOCKET"); } }
From source file:com.gazbert.bxbot.core.mail.EmailAlerter.java
public void sendMessage(String subject, String msgContent) { if (sendEmailAlertsEnabled) { final Session session = Session.getInstance(smtpProps, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpConfig.getAccountUsername(), smtpConfig.getAccountPassword()); }/*from w w w.java2 s . c o m*/ }); try { final Message message = new MimeMessage(session); message.setFrom(new InternetAddress(smtpConfig.getFromAddress())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(smtpConfig.getToAddress())); message.setSubject(subject); message.setText(msgContent); LOG.info(() -> "About to send following Email Alert with message content: " + msgContent); Transport.send(message); } catch (MessagingException e) { // not much we can do here, especially if the alert was critical - the bot is shutting down; just log it. LOG.error("Failed to send Email Alert. Details: " + e.getMessage(), e); } } else { LOG.warn("Email Alerts are disabled. Not sending the following message: Subject: " + subject + " Content: " + msgContent); } }
From source file:gov.nih.nci.caintegrator.web.action.registration.RegistrationAction.java
/** * Action to actually save the registration with authentication. * @return struts result./* w w w . j a v a 2s.c o m*/ */ public String save() { try { registrationRequest.setUptUrl(configurationHelper.getString(ConfigurationParameter.UPT_URL)); registrationService.registerUser(registrationRequest); return SUCCESS; } catch (MessagingException e) { addActionError( getText("struts.messages.error.registration.email.failure", new String[] { e.getMessage() })); return INPUT; } }
From source file:business.services.MailService.java
public void sendPasswordRecoveryToken(NewPasswordRequest npr) { try {// w w w. jav a2 s . co m MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); String recipient = npr.getUser().getContactData().getEmail(); message.setTo(recipient); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject(passwordRecoverySubject); String passwordRecoveryLink = getLink("/#/login/reset-password/" + npr.getToken()); message.setText(String.format(passwordRecoveryTemplate, passwordRecoveryLink)); log.info("Sending password recovery token to " + recipient + "."); mailSender.send(message.getMimeMessage()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } }
From source file:business.services.MailService.java
public void sendActivationEmail(@NotNull ActivationLink link) { // Send email to user try {/* w w w . j a va2s.c o m*/ MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); String recipient = link.getUser().getUsername(); message.setTo(recipient); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject("PALGA-account activeren / Activate PALGA account"); String activationLink = getLink("/#/activate/" + link.getToken()); message.setText(String.format(activationEmailTemplate, activationLink)); mailSender.send(message.getMimeMessage()); log.info("Activation link token generated for " + recipient + ": " + link.getToken()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } }
From source file:org.alfresco.tutorial.repoaction.SendAsEmailActionExecuter.java
@Override protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { if (serviceRegistry.getNodeService().exists(actionedUponNodeRef) == true) { // Get the email properties entered via Share Form String to = (String) action.getParameterValue(PARAM_EMAIL_TO_NAME); String subject = (String) action.getParameterValue(PARAM_EMAIL_SUBJECT_NAME); String body = (String) action.getParameterValue(PARAM_EMAIL_BODY_NAME); // Get document filename Serializable filename = serviceRegistry.getNodeService().getProperty(actionedUponNodeRef, ContentModel.PROP_NAME); if (filename == null) { throw new AlfrescoRuntimeException("Document filename is null"); }//from ww w . j av a 2 s. c om String documentName = (String) filename; try { // Create mail session Properties mailServerProperties = new Properties(); mailServerProperties = System.getProperties(); mailServerProperties.put("mail.smtp.host", "localhost"); mailServerProperties.put("mail.smtp.port", "2525"); Session session = Session.getDefaultInstance(mailServerProperties, null); session.setDebug(false); // Define message Message message = new MimeMessage(session); String fromAddress = "training@alfresco.com"; message.setFrom(new InternetAddress(fromAddress)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); // Create the message part with body text BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(body); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); // Create the Attachment part // // Get the document content bytes byte[] documentData = getDocumentContentBytes(actionedUponNodeRef, documentName); if (documentData == null) { throw new AlfrescoRuntimeException("Document content is null"); } // Attach document messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(documentData, new MimetypesFileTypeMap().getContentType(documentName)))); messageBodyPart.setFileName(documentName); multipart.addBodyPart(messageBodyPart); // Put parts in message message.setContent(multipart); // Send mail Transport.send(message); // Set status on node as "sent via email" Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); properties.put(ContentModel.PROP_ORIGINATOR, fromAddress); properties.put(ContentModel.PROP_ADDRESSEE, to); properties.put(ContentModel.PROP_SUBJECT, subject); properties.put(ContentModel.PROP_SENTDATE, new Date()); serviceRegistry.getNodeService().addAspect(actionedUponNodeRef, ContentModel.ASPECT_EMAILED, properties); } catch (MessagingException me) { me.printStackTrace(); throw new AlfrescoRuntimeException("Could not send email: " + me.getMessage()); } } }
From source file:business.services.MailService.java
@Transactional public void sendAgreementFormLink(@NotNull String email, @NotNull RequestProperties request) { log.info("Send agreement form link for request " + request.getRequestNumber() + "."); log.info("Sending link to " + email); try {//from w ww . j a va 2 s . com MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); message.setTo(email); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject(String.format("Nieuwe PALGA-aanvraag ontvangen, aanvraagnummer: %s", request.getRequestNumber())); String agreementFormLink = getLink("/#/request/" + request.getProcessInstanceId() + "/agreementform"); message.setText(String.format(requesterAgreementFormLinkTemplate, agreementFormLink)); mailSender.send(message.getMimeMessage()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } }
From source file:business.services.MailService.java
@Transactional public void notifyScientificCouncil(@NotNull RequestRepresentation request) { log.info("Notify scientic council for request " + request.getProcessInstanceId() + "."); List<User> members = userService.findScientificCouncilMembers(); for (User member : members) { log.info("Sending notification to user " + member.getUsername()); try {// w w w . java 2 s. co m MimeMessageHelper message = new MimeMessageHelper(mailSender.createMimeMessage()); message.setTo(member.getContactData().getEmail()); message.setFrom(getFrom(), fromName); message.setReplyTo(replyAddress, replyName); message.setSubject(String.format("Nieuwe PALGA-aanvraag aan u voorgelegd, aanvraagnummer: %s", request.getRequestNumber())); String requestLink = getLink("/#/request/view/" + request.getProcessInstanceId()); message.setText(String.format(scientificCouncilNotificationTemplate, requestLink)); mailSender.send(message.getMimeMessage()); } catch (MessagingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); throw new EmailError("Email error: " + e.getMessage()); } } }
From source file:com.sfs.dao.EmailMessageDAOImpl.java
/** * Send an email message using the configured Spring sender. On success * record the sent message in the datastore for reporting purposes * * @param emailMessage the email message * * @throws SFSDaoException the SFS dao exception *///from w ww. j a v a 2s. com public final void send(final EmailMessageBean emailMessage) throws SFSDaoException { // Check to see whether the required fields are set (to, from, message) if (StringUtils.isBlank(emailMessage.getTo())) { throw new SFSDaoException("Error recording email: Recipient " + "address required"); } if (StringUtils.isBlank(emailMessage.getFrom())) { throw new SFSDaoException("Error recording email: Email requires " + "a return address"); } if (StringUtils.isBlank(emailMessage.getMessage())) { throw new SFSDaoException("Error recording email: No email " + "message specified"); } if (javaMailSender == null) { throw new SFSDaoException("The EmailMessageDAO has not " + "been configured"); } // Prepare the email message MimeMessage message = javaMailSender.createMimeMessage(); MimeMessageHelper helper = null; if (emailMessage.getHtmlMessage()) { try { helper = new MimeMessageHelper(message, true, "UTF-8"); } catch (MessagingException me) { throw new SFSDaoException("Error preparing email for sending: " + me.getMessage()); } } else { helper = new MimeMessageHelper(message); } if (helper == null) { throw new SFSDaoException("The MimeMessageHelper cannot be null"); } try { if (StringUtils.isNotBlank(emailMessage.getTo())) { StringTokenizer tk = new StringTokenizer(emailMessage.getTo(), ","); while (tk.hasMoreTokens()) { String address = tk.nextToken(); helper.addTo(address); } } if (StringUtils.isNotBlank(emailMessage.getCC())) { StringTokenizer tk = new StringTokenizer(emailMessage.getCC(), ","); while (tk.hasMoreTokens()) { String address = tk.nextToken(); helper.addCc(address); } } if (StringUtils.isNotBlank(emailMessage.getBCC())) { StringTokenizer tk = new StringTokenizer(emailMessage.getBCC(), ","); while (tk.hasMoreTokens()) { String address = tk.nextToken(); helper.addBcc(address); } } if (StringUtils.isNotBlank(emailMessage.getFrom())) { if (StringUtils.isNotBlank(emailMessage.getFromName())) { try { helper.setFrom(emailMessage.getFrom(), emailMessage.getFromName()); } catch (UnsupportedEncodingException uee) { dataLogger.error("Error setting email from", uee); } } else { helper.setFrom(emailMessage.getFrom()); } } helper.setSubject(emailMessage.getSubject()); helper.setPriority(emailMessage.getPriority()); if (emailMessage.getHtmlMessage()) { final String htmlText = emailMessage.getMessage(); String plainText = htmlText; try { ConvertHtmlToText htmlToText = new ConvertHtmlToText(); plainText = htmlToText.convert(htmlText); } catch (Exception e) { dataLogger.error("Error converting HTML to plain text: " + e.getMessage()); } helper.setText(plainText, htmlText); } else { helper.setText(emailMessage.getMessage()); } helper.setSentDate(emailMessage.getSentDate()); } catch (MessagingException me) { throw new SFSDaoException("Error preparing email for sending: " + me.getMessage()); } // Append any attachments (if an HTML email) if (emailMessage.getHtmlMessage()) { for (String id : emailMessage.getAttachments().keySet()) { final Object reference = emailMessage.getAttachments().get(id); if (reference instanceof File) { try { FileSystemResource res = new FileSystemResource((File) reference); helper.addInline(id, res); } catch (MessagingException me) { dataLogger.error("Error appending File attachment: " + me.getMessage()); } } if (reference instanceof URL) { try { UrlResource res = new UrlResource((URL) reference); helper.addInline(id, res); } catch (MessagingException me) { dataLogger.error("Error appending URL attachment: " + me.getMessage()); } } } } // If not in debug mode send the email if (!debugMode) { deliver(emailMessage, message); } }