List of usage examples for javax.mail MessagingException getMessage
public String getMessage()
From source file:org.apache.axis2.transport.mail.server.MailSorter.java
private String getMailHeader(String headerName, MimeMessage mimeMessage) throws AxisFault { try {/*w w w.j a v a 2s. co m*/ String values[] = mimeMessage.getHeader(headerName); if (values != null) { return values[0]; } else { return null; } } catch (MessagingException e) { throw new AxisFault(e.getMessage(), e); } }
From source file:com.spartasystems.holdmail.util.TestMailClient.java
public void sendEmail(String fromEmail, String toEmail, String subject, String textBody, String htmlBody) { try {/*from ww w . j a va 2 s . c o m*/ Message message = new MimeMessage(session); message.setFrom(new InternetAddress(fromEmail)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail)); message.setSubject(subject); // Set the message createMultiMimePart(message, textBody, htmlBody); Transport.send(message); } catch (MessagingException e) { throw new HoldMailException("Failed to send email : " + e.getMessage(), e); } }
From source file:org.apache.james.transport.mailets.HeadersToHTTP.java
private void addHeader(Mail mail, boolean success, String errorMessage) { try {//from w w w. ja va 2s.co m MimeMessage message = mail.getMessage(); message.setHeader("X-headerToHTTP", (success ? "Succeeded" : "Failed")); if (!success && errorMessage != null && errorMessage.length() > 0) { message.setHeader("X-headerToHTTPFailure", errorMessage); } message.saveChanges(); } catch (MessagingException e) { log(e.getMessage()); } }
From source file:org.apache.james.transport.mailets.SerialiseToHTTP.java
private void addHeader(Mail mail, boolean success, String errorMessage) { try {/*from w ww . j av a 2 s . c o m*/ MimeMessage message = mail.getMessage(); message.setHeader("X-toHTTP", (success ? "Succeeded" : "Failed")); if (!success && errorMessage != null && errorMessage.length() > 0) { message.setHeader("X-toHTTPFailure", errorMessage); } message.saveChanges(); } catch (MessagingException e) { log(e.getMessage()); } }
From source file:org.xwiki.mail.internal.AttachmentMimeBodyPartFactoryTest.java
@Test public void createAttachmentBodyPartWhenWriteError() throws Exception { Environment environment = this.mocker.getInstance(Environment.class); when(environment.getTemporaryDirectory()).thenReturn(new File(TEMPORARY_DIRECTORY)); Attachment attachment = mock(Attachment.class); when(attachment.getFilename()).thenReturn("image.png"); when(attachment.getContent()).thenThrow(new RuntimeException("error")); try {/* ww w.j a va 2 s . c om*/ this.mocker.getComponentUnderTest().create(attachment, Collections.<String, Object>emptyMap()); fail("Should have thrown an exception here!"); } catch (MessagingException expected) { assertEquals("Failed to save attachment [image.png] to the file system", expected.getMessage()); } }
From source file:com.spartasystems.holdmail.util.TestMailClient.java
public void sendResourceEmail(String resourceName, String sender, String recipient, String subject) { try {/*ww w . j a v a2 s . c o m*/ InputStream resource = TestMailClient.class.getClassLoader().getResourceAsStream(resourceName); if (resource == null) { throw new MessagingException("Couldn't find resource at: " + resourceName); } Message message = new MimeMessage(session, resource); // wipe out ALL exisitng recipients message.setRecipients(Message.RecipientType.TO, new Address[] {}); message.setRecipients(Message.RecipientType.CC, new Address[] {}); message.setRecipients(Message.RecipientType.BCC, new Address[] {}); // then set the new data message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient)); message.setFrom(InternetAddress.parse(sender)[0]); message.setSubject(subject); Transport.send(message); logger.info("Outgoing mail forwarded to " + recipient); } catch (MessagingException e) { throw new HoldMailException("couldn't send mail: " + e.getMessage(), e); } }
From source file:org.alfresco.email.server.impl.subetha.SubethaEmailMessagePart.java
/** * Object can be built on existing message part only. * //from w w w. j ava 2 s . c o m * @param messagePart Message part. */ public SubethaEmailMessagePart(Part messagePart) { ParameterCheck.mandatory("messagePart", messagePart); try { fileSize = messagePart.getSize(); fileName = messagePart.getFileName(); contentType = messagePart.getContentType(); Matcher matcher = encodingExtractor.matcher(contentType); if (matcher.find()) { encoding = matcher.group(1); if (!Charset.isSupported(encoding)) { throw new EmailMessageException(ERR_UNSUPPORTED_ENCODING, encoding); } } try { contentInputStream = messagePart.getInputStream(); } catch (Exception ex) { throw new EmailMessageException(ERR_FAILED_TO_READ_CONTENT_STREAM, ex.getMessage()); } } catch (MessagingException e) { throw new EmailMessageException(ERR_INCORRECT_MESSAGE_PART, e.getMessage()); } }
From source file:org.apache.james.transport.mailets.HeadersToHTTP.java
/** * Takes the message, serialises it and sends it to the URL * /*from w ww. ja v a 2s . com*/ * @param mail * the mail being processed * */ public void service(Mail mail) { try { log(mail.getName() + "HeadersToHTTP: Starting"); MimeMessage message = mail.getMessage(); HashSet<NameValuePair> pairs = getNameValuePairs(message); log(mail.getName() + "HeadersToHTTP: " + pairs.size() + " named value pairs found"); String result = httpPost(pairs); if (passThrough) { addHeader(mail, true, result); } else { mail.setState(Mail.GHOST); } } catch (javax.mail.MessagingException me) { log(me.getMessage()); addHeader(mail, false, me.getMessage()); } catch (IOException e) { log(e.getMessage()); addHeader(mail, false, e.getMessage()); } }
From source file:org.apache.james.transport.mailets.SerialiseToHTTP.java
/** * Takes the message, serialises it and sends it to the URL * /*from w w w .ja v a 2s . co m*/ * @param mail * the mail being processed * */ public void service(Mail mail) { try { MimeMessage message = mail.getMessage(); String serialisedMessage = getSerialisedMessage(message); NameValuePair[] nameValuePairs = getNameValuePairs(serialisedMessage); String result = httpPost(nameValuePairs); if (passThrough) { addHeader(mail, (result == null || result.length() == 0), result); } else { mail.setState(Mail.GHOST); } } catch (javax.mail.MessagingException me) { log(me.getMessage()); addHeader(mail, false, me.getMessage()); } catch (IOException e) { log(e.getMessage()); addHeader(mail, false, e.getMessage()); } }
From source file:org.modelibra.util.Emailer.java
/** * Sends an email./*w w w . j a v a 2s .co m*/ * * @throws dmLite * exception if there is a problem */ public void send() throws ModelibraException { try { MimeMessage message = new MimeMessage(emailSession); InternetAddress fromIA = new InternetAddress(from); message.setFrom(fromIA); InternetAddress toIA = new InternetAddress(to); message.addRecipient(Message.RecipientType.TO, toIA); message.setSubject(subject); message.setText(content); emailStore.connect(outServer, code, password); Transport.send(message); emailStore.close(); } catch (MessagingException e) { throw new ModelibraException("Could not send an email: " + e.getMessage()); } catch (IllegalStateException e) { throw new ModelibraException("Could not send an email: " + e.getMessage()); } }