@Override public void run() { try { sendMessages(); } catch (MessagingException me) { Log.error(me.getMessage(), me); } }
/** * Fills the internal message queue if such queue is empty. This is due to * the fact that per single session there may be multiple messages retrieved * from the email server (see FETCH_SIZE). */ private synchronized void fillMessageQueueIfNecessary() { if (this.messageQueue.isEmpty()) { Object[] messages; try { messages = this.messageReceiver.receive(); } catch (MessagingException e) { String errorMsg = "Failed to receive messages from Email server: [" + e.getClass().getName() + " - " + e.getMessage(); this.getLogger().error(errorMsg); throw new ProcessException(errorMsg, e); } if (messages != null) { for (Object message : messages) { Assert.isTrue(message instanceof Message, "Message is not an instance of javax.mail.Message"); this.messageQueue.offer((Message) message); } } } }
Log.error(ae.getMessage(), ae);
+ e.getMessage(), e); } catch(JsonParseException e) { throw new VoldemortException("JSON parsing exception while trying to parse GET response "
+ e.getMessage(), e); } catch(JsonParseException e) { throw new VoldemortException("JSON parsing exception while trying to parse GET response "
@Test public void failedMimeMessage() throws MessagingException { MockJavaMailSender sender = new MockJavaMailSender(); sender.setHost("host"); sender.setUsername("username"); sender.setPassword("password"); MimeMessage mimeMessage1 = sender.createMimeMessage(); mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org")); mimeMessage1.setSubject("fail"); MimeMessage mimeMessage2 = sender.createMimeMessage(); mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org")); try { sender.send(mimeMessage1, mimeMessage2); } catch (MailSendException ex) { ex.printStackTrace(); assertEquals("host", sender.transport.getConnectedHost()); assertEquals("username", sender.transport.getConnectedUsername()); assertEquals("password", sender.transport.getConnectedPassword()); assertTrue(sender.transport.isCloseCalled()); assertEquals(1, sender.transport.getSentMessages().size()); assertEquals(mimeMessage2, sender.transport.getSentMessage(0)); assertEquals(1, ex.getFailedMessages().size()); assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next()); Object subEx = ex.getFailedMessages().values().iterator().next(); assertTrue(subEx instanceof MessagingException); assertEquals("failed", ((MessagingException) subEx).getMessage()); } }
@Test public void failedSimpleMessage() throws MessagingException { MockJavaMailSender sender = new MockJavaMailSender(); sender.setHost("host"); sender.setUsername("username"); sender.setPassword("password"); SimpleMailMessage simpleMessage1 = new SimpleMailMessage(); simpleMessage1.setTo("he@mail.org"); simpleMessage1.setSubject("fail"); SimpleMailMessage simpleMessage2 = new SimpleMailMessage(); simpleMessage2.setTo("she@mail.org"); try { sender.send(simpleMessage1, simpleMessage2); } catch (MailSendException ex) { ex.printStackTrace(); assertEquals("host", sender.transport.getConnectedHost()); assertEquals("username", sender.transport.getConnectedUsername()); assertEquals("password", sender.transport.getConnectedPassword()); assertTrue(sender.transport.isCloseCalled()); assertEquals(1, sender.transport.getSentMessages().size()); assertEquals(new InternetAddress("she@mail.org"), sender.transport.getSentMessage(0).getAllRecipients()[0]); assertEquals(1, ex.getFailedMessages().size()); assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next()); Object subEx = ex.getFailedMessages().values().iterator().next(); assertTrue(subEx instanceof MessagingException); assertEquals("failed", ((MessagingException) subEx).getMessage()); } }
/** * Sets the from header to the local address. * @param msg the target message. */ private void setDefaultFrom(final Message msg) { try { msg.setFrom(); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Sets the from header to the local address. * @param msg the target message. */ private void setDefaultFrom(final Message msg) { try { msg.setFrom(); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * It is assumed that file names are short and that in most cases * getTail will be the only method that will produce a result. * @param part to append to. * @param chunk non null string to append. */ private void appendFileName0(final Part part, String chunk) { try { //Remove all control character groups. chunk = chunk.replaceAll("[\\x00-\\x1F\\x7F]+", ""); final String old = part.getFileName(); part.setFileName(old != null ? old.concat(chunk) : chunk); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Sets the accept language to the default locale of the JVM. * If the locale is the root locale the header is not added. * @param p the part to set. * @since JavaMail 1.4.5 */ private void setAcceptLang(final Part p) { try { final String lang = LogManagerProperties .toLanguageTag(Locale.getDefault()); if (lang.length() != 0) { p.setHeader("Accept-Language", lang); } } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * It is assumed that file names are short and that in most cases * getTail will be the only method that will produce a result. * @param part to append to. * @param chunk non null string to append. */ private void appendFileName0(final Part part, String chunk) { try { //Remove all control character groups. chunk = chunk.replaceAll("[\\x00-\\x1F\\x7F]+", ""); final String old = part.getFileName(); part.setFileName(old != null ? old.concat(chunk) : chunk); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Used to signal that body parts are missing from a message. Also used * when LogRecords were passed to an attachment formatter but the formatter * produced no output, which is allowed. Used during a verify because all * parts are omitted, none of the content formatters are used. This is * not used when a filter prevents LogRecords from being formatted. * This header is defined in RFC 2156 and RFC 4021. * @param msg the message. * @since JavaMail 1.4.5 */ private void setIncompleteCopy(final Message msg) { try { msg.setHeader("Incomplete-Copy", ""); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Sets the accept language to the default locale of the JVM. * If the locale is the root locale the header is not added. * @param p the part to set. * @since JavaMail 1.4.5 */ private void setAcceptLang(final Part p) { try { final String lang = LogManagerProperties .toLanguageTag(Locale.getDefault()); if (lang.length() != 0) { p.setHeader("Accept-Language", lang); } } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Signals that this message was generated by automatic process. * This header is defined in RFC 3834 section 5. * @param msg the message. * @since JavaMail 1.4.6 */ private void setAutoSubmitted(final Message msg) { if (allowRestrictedHeaders()) { try { //RFC 3834 (5.2) msg.setHeader("auto-submitted", "auto-generated"); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } } }
/** * Signals that this message was generated by automatic process. * This header is defined in RFC 3834 section 5. * @param msg the message. * @since JavaMail 1.4.6 */ private void setAutoSubmitted(final Message msg) { if (allowRestrictedHeaders()) { try { //RFC 3834 (5.2) msg.setHeader("auto-submitted", "auto-generated"); } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } } }
/** * Sets the priority and importance headers. * @param msg the target message. */ private void setPriority(final Message msg) { try { msg.setHeader("Importance", "High"); msg.setHeader("Priority", "urgent"); msg.setHeader("X-Priority", "2"); //High } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Sets the priority and importance headers. * @param msg the target message. */ private void setPriority(final Message msg) { try { msg.setHeader("Importance", "High"); msg.setHeader("Priority", "urgent"); msg.setHeader("X-Priority", "2"); //High } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } }
/** * Sets reply-to address header. * @param msg the target message. */ private void setReplyTo(final Message msg) { final String reply = getSession(msg).getProperty("mail.reply.to"); if (!isEmpty(reply)) { try { final Address[] address = InternetAddress.parse(reply, false); if (address.length > 0) { msg.setReplyTo(address); } } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } } }
/** * Sets reply-to address header. * @param msg the target message. */ private void setReplyTo(final Message msg) { final String reply = getSession(msg).getProperty("mail.reply.to"); if (!isEmpty(reply)) { try { final Address[] address = InternetAddress.parse(reply, false); if (address.length > 0) { msg.setReplyTo(address); } } catch (final MessagingException ME) { reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE); } } }