Example usage for javax.mail.internet MimeMessage getSubject

List of usage examples for javax.mail.internet MimeMessage getSubject

Introduction

In this page you can find the example usage for javax.mail.internet MimeMessage getSubject.

Prototype

@Override
public String getSubject() throws MessagingException 

Source Link

Document

Returns the value of the "Subject" header field.

Usage

From source file:org.apereo.portal.portlets.account.EmailPasswordResetNotificationImpl.java

@Override
public void sendNotification(URL resetUrl, ILocalAccountPerson account, Locale locale) {
    log.debug("Sending password reset instructions to user with url {}", resetUrl.toString());

    try {//from ww  w. ja v a  2s .  c  o m
        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        String email = (String) account.getAttributeValue(ILocalAccountPerson.ATTR_MAIL);
        String subject = messageSource.getMessage(subjectMessageKey, new Object[] {}, locale);
        String body = formatBody(resetUrl, account, locale);

        helper.addTo(email);
        helper.setText(body, true);
        helper.setSubject(subject);
        helper.setFrom(portalEmailAddress, messageSource.getMessage("portal.name", new Object[] {}, locale));

        log.debug("Sending message to {} from {} subject {}", email, Arrays.toString(message.getFrom()),
                message.getSubject());
        this.mailSender.send(helper.getMimeMessage());

    } catch (Exception e) {
        log.error("Unable to send password reset email", e);
    }
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendASimpleEmail() throws BonitaException, MessagingException, InterruptedException {
    executeConnector(getBasicSettings());
    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());//w  ww  .jav  a2 s. c o m
    final WiserMessage message = messages.get(0);
    assertNotNull(message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void testSendEmailWithFromAddress() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("from", ADDRESSMARK);
    executeConnector(parameters);//from w  w  w .j  a  v a 2  s  . co  m
    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void testSendEmailWithAutentication() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("userName", "john");
    parameters.put("password", "doe");
    executeConnector(parameters);//  w  w w  .  jav a2s . c  o  m
    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertNotNull(message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithToRecipientsAddresses() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("to", ADDRESSJOHN + ", " + ADDRESSPATTY);
    parameters.put("from", ADDRESSMARK);
    executeConnector(parameters);/*w w  w  .  j  a  va  2 s  .  c  om*/
    final List<WiserMessage> messages = server.getMessages();
    assertEquals(2, messages.size());
    WiserMessage message = messages.get(0);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());

    message = messages.get(1);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSPATTY, message.getEnvelopeReceiver());
    mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithCcRecipientsAddresses() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("cc", ADDRESSPATTY);
    parameters.put("from", ADDRESSMARK);
    executeConnector(parameters);/*from www . ja v a2s  . c o m*/

    List<WiserMessage> messages = server.getMessages();
    assertEquals(2, messages.size());
    WiserMessage message = messages.get(0);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());

    message = messages.get(1);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSPATTY, message.getEnvelopeReceiver());
    mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());

    parameters.put("cc", ADDRESSPATTY + ", " + ADDRESSMARK);
    executeConnector(parameters);
    messages = server.getMessages();
    assertEquals(5, messages.size());
    message = messages.get(4);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSMARK, message.getEnvelopeReceiver());
    mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithPlainMessage() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("message", PLAINMESSAGE);
    parameters.put("from", ADDRESSMARK);
    executeConnector(parameters);//from   w w w. j  a  va2 s. c o m

    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertTrue(mime.getContentType().contains(TEXT_PLAIN));
    assertEquals(PLAINMESSAGE, mime.getContent());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithHtmlMessage() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("html", true);
    parameters.put("message", HTMLMESSAGE);
    parameters.put("from", ADDRESSMARK);
    executeConnector(parameters);// ww  w .j  a  v a 2  s . c  om

    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertEquals(ADDRESSMARK, message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertTrue(mime.getContentType().contains(TEXT_HTML));
    assertEquals(HTMLMESSAGE, mime.getContent());
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendEmailWithExtraHeaders() throws Exception {
    final List<List<String>> headers = new ArrayList<List<String>>();
    List<String> row1 = new ArrayList<String>();
    row1.add("X-Mailer");
    row1.add("Bonita Mailer");
    headers.add(row1);/*from   w w w. j  a va  2s  . co m*/

    List<String> row2 = new ArrayList<String>();
    row2.add("Message-ID");
    row2.add("IWantToHackTheServer");
    headers.add(row2);

    List<String> row3 = new ArrayList<String>();
    row3.add("X-Priority");
    row3.add("2 (High)");
    headers.add(row3);

    List<String> row4 = new ArrayList<String>();
    row4.add("Content-Type");
    row4.add("video/mpeg");
    headers.add(row4);

    List<String> row5 = new ArrayList<String>();
    row5.add("WhatIWant");
    row5.add("anyValue");
    headers.add(row5);

    List<String> row6 = new ArrayList<String>();
    row6.add("From");
    row6.add("alice@bob.charly");
    headers.add(row6);

    List<String> row7 = new ArrayList<String>();
    row7.add(null);
    row7.add(null);
    headers.add(row7);

    final Map<String, Object> parameters = getBasicSettings();

    parameters.put("headers", headers);

    executeConnector(parameters);

    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertEquals("alice@bob.charly", message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(SUBJECT, mime.getSubject());
    assertEquals(0, mime.getSize());
    assertEquals("Bonita Mailer", mime.getHeader("X-Mailer", ""));
    assertEquals("2 (High)", mime.getHeader("X-Priority", ""));
    assertEquals("anyValue", mime.getHeader("WhatIWant", ""));
    assertNotSame("alice@bob.charly", mime.getHeader("From"));
    assertFalse(mime.getContentType().contains("video/mpeg"));
    assertNotSame("IWantToHackTheServer", mime.getHeader("Message-ID"));
}

From source file:org.bonitasoft.connectors.email.test.EmailConnectorTest.java

@Test
public void sendCyrillicEmail() throws Exception {
    final Map<String, Object> parameters = getBasicSettings();
    parameters.put("subject", CYRILLIC_SUBJECT);
    parameters.put("message", CYRILLIC_MESSAGE);
    executeConnector(parameters);//from  w w w .  ja  v a 2s  . c o  m

    final List<WiserMessage> messages = server.getMessages();
    assertEquals(1, messages.size());
    final WiserMessage message = messages.get(0);
    assertNotNull(message.getEnvelopeSender());
    assertEquals(ADDRESSJOHN, message.getEnvelopeReceiver());
    final MimeMessage mime = message.getMimeMessage();
    assertEquals(CYRILLIC_SUBJECT, mime.getSubject());
    assertTrue(mime.getContentType().contains(TEXT_PLAIN));
    assertEquals(CYRILLIC_MESSAGE, mime.getContent());
}