List of usage examples for org.apache.commons.mail MultiPartEmail getSubject
public String getSubject()
From source file:core.messaging.Messenger.java
private void sendImmediately(final String to, final String from, final String subject, final String body, ByteArrayDataSource attachment) { try {/*from ww w . j a v a 2s. co m*/ logger.log(Level.INFO, "Sending email to={0},from={1},subject={2},body={3},attachment={4},fileName{5},mimeType={6}", new Object[] { to, from, subject, body, attachment, attachment == null ? "null" : attachment.getName(), attachment == null ? "null" : attachment.getContentType() }); // Create the email message MultiPartEmail email = new MultiPartEmail(); email.addTo(to); email.setFrom(from); email.setSubject(subject); email.setMsg(body); String logLocation = Play.configuration.getProperty("log.mail"); logger.log(Level.FINE, "logging message to {0}, attachment size={1}", new Object[] { logLocation, attachment == null ? 0 : attachment.getBytes().length }); long timestamp = System.currentTimeMillis(); //TODO * log email contents also (body) FileLogHelper.createInstance().log(logLocation, to + "-" + timestamp, email.getSubject().getBytes()); if (attachment != null) { String attachmentName = to + "-" + timestamp + "-attachment-" + attachment.getName(); FileLogHelper.createInstance().log(logLocation, attachmentName, attachment.getBytes()); // add the attachment EmailAttachment emailAttachment = new EmailAttachment(); //write to mailerbean dir then read from there, that is fine emailAttachment.setPath(logLocation + "/" + attachmentName); emailAttachment.setDisposition(EmailAttachment.ATTACHMENT); emailAttachment.setDescription(attachment.getName()); emailAttachment.setName(attachment.getName()); email.attach(emailAttachment); } logger.log(Level.FINE, "Sending message"); Future<Boolean> send = Mail.send(email); } catch (Exception ex) { Logger.getLogger(Messenger.class.getName()).log(Level.SEVERE, null, ex); throw new MessangerException(ex); } }
From source file:ninja.postoffice.commonsmail.CommonsMailHelperImplTest.java
/** * Note:/*from w w w . ja v a 2 s . co m*/ * - Setting of header parameters not (yet) tested as we cannot get back the headers set easily. * * * @throws Exception */ @Test public void testDoPopulateMultipartMailWithContent() throws Exception { Mail mail = MailImplTestHelper.getMailImplWithDemoContent(); MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail); commonsmailHelper.doPopulateMultipartMailWithContent(multiPartEmail, mail); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc2@domain"))); assertEquals("subject", multiPartEmail.getSubject()); assertEquals(new InternetAddress("from1@domain"), multiPartEmail.getFromAddress()); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getReplyToAddresses()) .contains(new InternetAddress("replyTo1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getReplyToAddresses()) .contains(new InternetAddress("replyTo2@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getCcAddresses()) .contains(new InternetAddress("cc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getCcAddresses()) .contains(new InternetAddress("cc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc2@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getToAddresses()) .contains(new InternetAddress("to1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getToAddresses()) .contains(new InternetAddress("to2@domain"))); }