javax.mail.Message.getRecipients()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中javax.mail.Message.getRecipients()方法的一些代码示例,展示了Message.getRecipients()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getRecipients()方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:getRecipients

Message.getRecipients介绍

[英]Get all the recipient addresses of the given type.

This method returns null if no recipients of the given type are present in this message. It may return an empty array if the header is present, but contains no addresses.
[中]获取给定类型的所有收件人地址。
如果此邮件中不存在给定类型的收件人,此方法将返回null。如果报头存在,它可能会返回一个空数组,但不包含地址。

代码示例

代码示例来源:origin: aws/aws-sdk-java

if ( !isNullOrEmpty(m.getRecipients(Message.RecipientType.TO)) ) {
  for ( Address a : m.getRecipients(Message.RecipientType.TO) ) {
    addressTable.put(a, Message.RecipientType.TO);
if ( !isNullOrEmpty(m.getRecipients(Message.RecipientType.CC)) ) {
  for ( Address a : m.getRecipients(Message.RecipientType.CC) ) {
    addressTable.put(a, Message.RecipientType.CC);
if ( !isNullOrEmpty(m.getRecipients(Message.RecipientType.BCC)) ) {
  for ( Address a : m.getRecipients(Message.RecipientType.BCC) ) {
    addressTable.put(a, Message.RecipientType.BCC);
if ( m.getRecipients(Message.RecipientType.TO) == null ||
    m.getRecipients(Message.RecipientType.TO).length == 0 ) {
  m.setRecipient(Message.RecipientType.TO, addressTable.keySet().iterator().next());

代码示例来源:origin: aws/aws-sdk-java

&& isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.TO))
  && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.CC))
  && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.BCC)) ) {
throw new SendFailedException("No recipient addresses");
  m.getRecipients(Message.RecipientType.TO),
  m.getRecipients(Message.RecipientType.CC),
  m.getRecipients(Message.RecipientType.BCC),
  addresses } ) {
if ( !isNullOrEmpty(recipients) ) {

代码示例来源:origin: azkaban/azkaban

private void retrySendMessage(final JavaxMailSender s, final Message message)
  throws MessagingException {
 int attempt;
 for (attempt = 0; attempt < MAX_EMAIL_RETRY_COUNT; attempt++) {
  try {
   s.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
   return;
  } catch (final Exception e) {
   this.logger.error("Sending email messages failed, attempt: " + attempt, e);
  }
 }
 s.close();
 throw new MessagingException("Failed to send email messages after "
   + attempt + " attempts.");
}

代码示例来源:origin: azkaban/azkaban

@Before
public void setUp() throws Exception {
 this.creator = mock(EmailMessageCreator.class);
 this.mailSender = mock(JavaxMailSender.class);
 this.mimeMessage = mock(Message.class);
 this.addresses = new Address[]{new InternetAddress(this.toAddr, false)};
 when(this.creator.createSender(any())).thenReturn(this.mailSender);
 when(this.mailSender.createMessage()).thenReturn(this.mimeMessage);
 when(this.mimeMessage.getRecipients(Message.RecipientType.TO)).thenReturn(this.addresses);
 this.em = new EmailMessage(this.host, this.port, this.user, this.password, this.creator);
}

代码示例来源:origin: oblac/jodd

@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());
}

代码示例来源:origin: apache/nifi

assertEquals("X-Mailer Header", "TestingNíFiNonASCII", MimeUtility.decodeText(message.getHeader("X-Mailer")[0]));
assertEquals("the message body", message.getContent());
assertEquals(1, message.getRecipients(RecipientType.TO).length);
assertEquals("to@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertEquals(1, message.getRecipients(RecipientType.BCC).length);
assertEquals("bcc@apache.org", message.getRecipients(RecipientType.BCC)[0].toString());
assertEquals(1, message.getRecipients(RecipientType.CC).length);
assertEquals("cc@apache.org",message.getRecipients(RecipientType.CC)[0].toString());
assertEquals("bulk", MimeUtility.decodeText(message.getHeader("Precedence")[0]));
assertEquals("búlk", MimeUtility.decodeText(message.getHeader("PrecedenceEncodeDecodeTest")[0]));

代码示例来源:origin: oblac/jodd

to(msg.getRecipients(Message.RecipientType.TO));
cc(msg.getRecipients(Message.RecipientType.CC));

代码示例来源:origin: apache/nifi

assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("Some Text", message.getContent());
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertEquals("another@apache.org", message.getRecipients(RecipientType.TO)[1].toString());
assertEquals("recipientcc@apache.org", message.getRecipients(RecipientType.CC)[0].toString());
assertEquals("anothercc@apache.org", message.getRecipients(RecipientType.CC)[1].toString());
assertEquals("recipientbcc@apache.org", message.getRecipients(RecipientType.BCC)[0].toString());
assertEquals("anotherbcc@apache.org", message.getRecipients(RecipientType.BCC)[1].toString());

代码示例来源:origin: apache/nifi

@Test
public void testOutgoingMessage() throws Exception {
  // verifies that are set on the outgoing Message correctly
  runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
  runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
  runner.setProperty(PutEmail.FROM, "test@apache.org");
  runner.setProperty(PutEmail.MESSAGE, "Message Body");
  runner.setProperty(PutEmail.TO, "recipient@apache.org");
  runner.enqueue("Some Text".getBytes());
  runner.run();
  runner.assertQueueEmpty();
  runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
  // Verify that the Message was populated correctly
  assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
  Message message = processor.getMessages().get(0);
  assertEquals("test@apache.org", message.getFrom()[0].toString());
  assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
  assertEquals("Message Body", message.getContent());
  assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
  assertNull(message.getRecipients(RecipientType.BCC));
  assertNull(message.getRecipients(RecipientType.CC));
}

代码示例来源:origin: camunda/camunda-bpm-platform

Address[] to = getRecipients(RecipientType.TO);
Address[] cc = getRecipients(RecipientType.CC);
Address[] bcc = getRecipients(RecipientType.BCC);

代码示例来源:origin: apache/nifi

assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertEquals("Some text", text);
assertNull(message.getRecipients(RecipientType.BCC));
assertNull(message.getRecipients(RecipientType.CC));

代码示例来源:origin: com.sun.mail/javax.mail

Address[] to = getRecipients(RecipientType.TO);
Address[] cc = getRecipients(RecipientType.CC);
Address[] bcc = getRecipients(RecipientType.BCC);

代码示例来源:origin: oblac/jodd

@Test
void testSimpleTextWithCyrilic() throws MessagingException, IOException {
  final Email email = Email.create()
    .from("Тијана Милановић <t@gmail.com>")
    .to("Јодд <i@jodd.com>")
    .subject("Здраво!")
    .textMessage("шта радиш?");
  final Message message = createMessage(email);
  final String content = (String) message.getContent();
  assertEquals("шта радиш?", content);
  assertTrue(message.getDataHandler().getContentType().contains("text/plain"));
  assertEquals("=?UTF-8?B?0KLQuNGY0LDQvdCwINCc0LjQu9Cw0L3QvtCy0LjRmw==?= <t@gmail.com>", message.getFrom()[0].toString());
  assertEquals("=?UTF-8?B?0IjQvtC00LQ=?= <i@jodd.com>", message.getRecipients(RecipientType.TO)[0].toString());
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Check whether the address specified in the constructor is
 * a substring of the recipient address of this Message.
 *
 * @param   msg     The comparison is applied to this Message's recipient
 *                address.
 * @return          true if the match succeeds, otherwise false.
 */
public boolean match(Message msg) {
Address[] recipients;
try {
  recipients = msg.getRecipients(type);
} catch (Exception e) {
  return false;
}
if (recipients == null)
  return false;

for (int i=0; i < recipients.length; i++)
  if (super.match(recipients[i]))
  return true;
return false;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * The match method.
 *
 * @param msg    The address match is applied to this Message's recepient
 *            address
 * @return        true if the match succeeds, otherwise false
 */
public boolean match(Message msg) {
Address[] recipients;
try {
   recipients = msg.getRecipients(type);
} catch (Exception e) {
  return false;
}
if (recipients == null)
  return false;
for (int i=0; i < recipients.length; i++)
  if (super.match(recipients[i]))
  return true;
return false;
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * The match method.
 *
 * @param msg    The address match is applied to this Message's recepient
 *            address
 * @return        true if the match succeeds, otherwise false
 */
@Override
public boolean match(Message msg) {
Address[] recipients;
try {
   recipients = msg.getRecipients(type);
} catch (Exception e) {
  return false;
}
if (recipients == null)
  return false;
for (int i=0; i < recipients.length; i++)
  if (super.match(recipients[i]))
  return true;
return false;
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Check whether the address specified in the constructor is
 * a substring of the recipient address of this Message.
 *
 * @param   msg     The comparison is applied to this Message's recipient
 *                address.
 * @return          true if the match succeeds, otherwise false.
 */
@Override
public boolean match(Message msg) {
Address[] recipients;
try {
  recipients = msg.getRecipients(type);
} catch (Exception e) {
  return false;
}
if (recipients == null)
  return false;

for (int i=0; i < recipients.length; i++)
  if (super.match(recipients[i]))
  return true;
return false;
}

代码示例来源:origin: oblac/jodd

@Test
void testTextHtml() throws MessagingException, IOException {
  final Email email = Email.create()
    .from(FROM_EXAMPLE_COM)
    .to(TO_EXAMPLE_COM)
    .subject(SUB)
    .textMessage(HELLO)
    .htmlMessage("<html><body><h1>Hey!</h1></body></html>");
  final Message message = createMessage(email);
  assertEquals(1, message.getFrom().length);
  assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
  assertEquals(1, message.getRecipients(RecipientType.TO).length);
  assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
  assertEquals(SUB, message.getSubject());
  // wrapper
  final MimeMultipart multipart = (MimeMultipart) message.getContent();
  assertEquals(1, multipart.getCount());
  assertTrue(multipart.getContentType().contains("multipart/mixed"));
  // inner content
  final MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0);
  final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent();
  assertEquals(2, mimeMultipart.getCount());
  assertTrue(mimeMultipart.getContentType().contains("multipart/alternative"));
  MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0);
  assertEquals(HELLO, bodyPart.getContent());
  assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_PLAIN));
  bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(1);
  assertEquals("<html><body><h1>Hey!</h1></body></html>", bodyPart.getContent());
  assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_HTML));
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * Map the message headers to a Map using {@link MailHeaders} keys; specifically
 * maps the address headers and the subject.
 * @param source the message.
 * @return the map.
 */
public static Map<String, Object> extractStandardHeaders(Message source) {
  Map<String, Object> headers = new HashMap<String, Object>();
  try {
    headers.put(MailHeaders.FROM, convertToString(source.getFrom()));
    headers.put(MailHeaders.BCC, convertToStringArray(source.getRecipients(RecipientType.BCC)));
    headers.put(MailHeaders.CC, convertToStringArray(source.getRecipients(RecipientType.CC)));
    headers.put(MailHeaders.TO, convertToStringArray(source.getRecipients(RecipientType.TO)));
    headers.put(MailHeaders.REPLY_TO, convertToString(source.getReplyTo()));
    headers.put(MailHeaders.SUBJECT, source.getSubject());
    return headers;
  }
  catch (Exception e) {
    throw new MessagingException("conversion of MailMessage headers failed", e);
  }
}

代码示例来源:origin: oblac/jodd

assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
assertEquals(1, message.getRecipients(RecipientType.TO).length);
assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());

相关文章