/** * Appends BCC address. * * @param personalName personal name. * @param bcc email address. * @return this * @see #bcc(EmailAddress) */ public Email bcc(final String personalName, final String bcc) { return bcc(new EmailAddress(personalName, bcc)); }
/** * Appends BCC address. * * @param bccs array of {@link Address}es to set. * @return this * @see #bcc(EmailAddress...) */ public Email bcc(final Address... bccs) { return bcc(EmailAddress.of(bccs)); }
/** * Appends BCC address. * * @param bcc Address may be specified with personal name like this: {@code Jenny Doe <email@foo.com>}. * @return this * @see #bcc(EmailAddress) */ public Email bcc(final String bcc) { return bcc(EmailAddress.of(bcc)); }
/** * Appends BCC address. * * @param bcc {@link Address} to add. * @return this * @see #bcc(EmailAddress) */ public Email bcc(final Address bcc) { return bcc(EmailAddress.of(bcc)); }
/** * Appends BCC address. * * @param bccs array of {@link String}s to set. * @return this * @see #bcc(EmailAddress...) */ public Email bcc(final String... bccs) { return bcc(EmailAddress.of(bccs)); }
/** * Sets TO, CC and BCC in msgToSet with TO, CC and BCC from emailWithData. * * @param emailWithData {@link Email} with data * @param msgToSet {@link MimeMessage} to set data into. * @throws MessagingException if there is a failure. */ private void setRecipients(final Email emailWithData, final MimeMessage msgToSet) throws MessagingException { // TO final InternetAddress[] to = EmailAddress.convert(emailWithData.to()); if (to.length > 0) { msgToSet.setRecipients(RecipientType.TO, to); } // CC final InternetAddress[] cc = EmailAddress.convert(emailWithData.cc()); if (cc.length > 0) { msgToSet.setRecipients(RecipientType.CC, cc); } // BCC final InternetAddress[] bcc = EmailAddress.convert(emailWithData.bcc()); if (bcc.length > 0) { msgToSet.setRecipients(RecipientType.BCC, bcc); } }
@Override public Email clone() { return create() // from / reply-to .from(from()) .replyTo(replyTo()) // recipients .to(to()) .cc(cc()) .bcc(bcc()) // subject .subject(subject(), subjectEncoding()) // dates .sentDate(sentDate()) // headers - includes priority .headers(headers()) // content / attachments .storeAttachments(attachments()) .message(messages()); }
@Test void testFromToBccCc() throws MessagingException { final Email email = Email.create() .from(FROM_EXAMPLE_COM) .to(TO1_EXAMPLE_COM).to("Major Tom", "to2@example.com") .cc(CC1_EXAMPLE_COM).cc("Major Carson", "cc2@example.com") .bcc("Major Ben", "bcc1@example.com").bcc(BCC2_EXAMPLE_COM); final Message message = createMessage(email); assertEquals(1, message.getFrom().length); assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString()); assertEquals(6, message.getAllRecipients().length); assertEquals(2, message.getRecipients(RecipientType.TO).length); assertEquals(TO1_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString()); assertEquals("Major Tom <to2@example.com>", message.getRecipients(RecipientType.TO)[1].toString()); assertEquals(2, message.getRecipients(RecipientType.CC).length); assertEquals(CC1_EXAMPLE_COM, message.getRecipients(RecipientType.CC)[0].toString()); assertEquals("Major Carson <cc2@example.com>", message.getRecipients(RecipientType.CC)[1].toString()); assertEquals(2, message.getRecipients(RecipientType.BCC).length); assertEquals("Major Ben <bcc1@example.com>", message.getRecipients(RecipientType.BCC)[0].toString()); assertEquals(BCC2_EXAMPLE_COM, message.getRecipients(RecipientType.BCC)[1].toString()); }
/** * Appends BCC address. * * @param bcc Address may be specified with personal name like this: {@code Jenny Doe <email@foo.com>}. * @return this * @see #bcc(EmailAddress) */ public Email bcc(final String bcc) { return bcc(EmailAddress.of(bcc)); }
/** * Appends BCC address. * * @param personalName personal name. * @param bcc email address. * @return this * @see #bcc(EmailAddress) */ public Email bcc(final String personalName, final String bcc) { return bcc(new EmailAddress(personalName, bcc)); }
/** * Appends BCC address. * * @param bcc {@link Address} to add. * @return this * @see #bcc(EmailAddress) */ public Email bcc(final Address bcc) { return bcc(EmailAddress.of(bcc)); }
/** * Appends BCC address. * * @param bccs array of {@link String}s to set. * @return this * @see #bcc(EmailAddress...) */ public Email bcc(final String... bccs) { return bcc(EmailAddress.of(bccs)); }
/** * Appends BCC address. * * @param bccs array of {@link Address}es to set. * @return this * @see #bcc(EmailAddress...) */ public Email bcc(final Address... bccs) { return bcc(EmailAddress.of(bccs)); }
/** * Sets TO, CC and BCC in msgToSet with TO, CC and BCC from emailWithData. * * @param emailWithData {@link Email} with data * @param msgToSet {@link MimeMessage} to set data into. * @throws MessagingException if there is a failure. */ private void setRecipients(final Email emailWithData, final MimeMessage msgToSet) throws MessagingException { // TO final InternetAddress[] to = EmailAddress.convert(emailWithData.to()); if (to.length > 0) { msgToSet.setRecipients(RecipientType.TO, to); } // CC final InternetAddress[] cc = EmailAddress.convert(emailWithData.cc()); if (cc.length > 0) { msgToSet.setRecipients(RecipientType.CC, cc); } // BCC final InternetAddress[] bcc = EmailAddress.convert(emailWithData.bcc()); if (bcc.length > 0) { msgToSet.setRecipients(RecipientType.BCC, bcc); } }
@Override public Email clone() { return create() // from / reply-to .from(from()) .replyTo(replyTo()) // recipients .to(to()) .cc(cc()) .bcc(bcc()) // subject .subject(subject(), subjectEncoding()) // dates .sentDate(sentDate()) // headers - includes priority .headers(headers()) // content / attachments .storeAttachments(attachments()) .message(messages()); }