Example usage for org.apache.commons.mail MultiPartEmail addPart

List of usage examples for org.apache.commons.mail MultiPartEmail addPart

Introduction

In this page you can find the example usage for org.apache.commons.mail MultiPartEmail addPart.

Prototype

public Email addPart(final MimeMultipart multipart, final int index) throws EmailException 

Source Link

Document

Add a new part to the email.

Usage

From source file:org.chenillekit.mail.services.TestMailService.java

@Test
public void test_multipartemail_sending() throws EmailException, MessagingException {
    MultiPartEmail email = new MultiPartEmail();
    email.setSubject("Test Mail 2");
    email.addTo("homburgs@gmail.com");
    email.setFrom("homburgs@gmail.com");
    email.setMsg("This is a dummy message text!");
    email.addPart("This is a dummy message part 1!", "text/plain");

    MimeMultipart mmp = new MimeMultipart();
    MimeBodyPart mbp = new MimeBodyPart();

    mbp.setText("This is a dummy MimeBodyPart 1!");

    mmp.addBodyPart(mbp);/* w  w  w. ja va  2s .c  o  m*/
    email.addPart(mmp);

    EmailAttachment attachment = new EmailAttachment();
    attachment.setDescription("dummy.txt");
    attachment.setURL(new ClasspathResource("dummy.txt").toURL());
    email.attach(attachment);

    MailService mailService = registry.getService(MailService.class);
    boolean sended = mailService.sendEmail(email);

    assertTrue(sended, "sended");
}