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

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

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

Message.getAllRecipients介绍

[英]Get all the recipient addresses for the message. The default implementation extracts the TO, CC, and BCC recipients using the getRecipients method.

This method returns null if none of the recipient headers are present in this message. It may Return an empty array if any recipient header is present, but contains no addresses.
[中]获取邮件的所有收件人地址。默认实现使用getRecipients方法提取收件人、抄送收件人和密件抄送收件人。
如果此邮件中没有收件人标头,则此方法返回null。如果存在任何收件人标头,但不包含地址,则可能返回空数组。

代码示例

代码示例来源:origin: javaee-samples/javaee7-samples

Transport.send(message, message.getAllRecipients());

代码示例来源:origin: javaee-samples/javaee7-samples

t.sendMessage(message, message.getAllRecipients());

代码示例来源:origin: aa112901/remusic

mailMessage.setSentDate(new Date());
mailMessage.setText(content);
transport.sendMessage(mailMessage, mailMessage.getAllRecipients());
return true;

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

@Override
  public void sendMessage(Message message, Address[] addresses) throws MessagingException {
    if ("fail".equals(message.getSubject())) {
      throw new MessagingException("failed");
    }
    if (addresses == null || (message.getAllRecipients() == null ? addresses.length > 0 :
        !ObjectUtils.nullSafeEquals(addresses, message.getAllRecipients()))) {
      throw new MessagingException("addresses not correct");
    }
    if (message.getSentDate() == null) {
      throw new MessagingException("No sentDate specified");
    }
    if (message.getSubject() != null && message.getSubject().contains("custom")) {
      assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate());
    }
    this.sentMessages.add(message);
  }
}

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

Address[] sent = new Address[0];
Address[] unsent = new Address[0];
Address[] invalid = m.getAllRecipients();
super.notifyTransportListeners(
    TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent,

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

SendRawEmailResult resp = this.emailService.sendRawEmail(req);
  lastMessageId = resp.getMessageId();
  sent = m.getAllRecipients();
  unsent = new Address[0];
  invalid = new Address[0];
} catch (Exception e) {
  sent = new Address[0];
  unsent = m.getAllRecipients();
  invalid = new Address[0];
  super.notifyTransportListeners(

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

session.getProperty("mail." + protocol + ".password"));
  tr.sendMessage(msg, msg.getAllRecipients());
} finally {
  tr.close();

代码示例来源:origin: pentaho/pentaho-kettle

break;
case MailInputField.COLUMN_RECIPIENTS:
 r[index] = StringUtils.join( message.getAllRecipients(), ";" );
 break;
case MailInputField.COLUMN_DESCRIPTION:

代码示例来源:origin: pentaho/pentaho-kettle

transport.connect();
 transport.sendMessage( msg, msg.getAllRecipients() );
} finally {
 if ( transport != null ) {

代码示例来源:origin: pentaho/pentaho-kettle

when( message.getAllRecipients() ).thenReturn( adrRecip );
when( message.getDescription() ).thenReturn( DESC );
when( message.getReceivedDate() ).thenReturn( DATE1 );

代码示例来源:origin: pentaho/pentaho-kettle

transport.connect();
 transport.sendMessage( msg, msg.getAllRecipients() );
} finally {
 if ( transport != null ) {

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

session.getProvenanceReporter().send(flowFile, "mailto:" + message.getAllRecipients()[0].toString());
session.transfer(flowFile, REL_SUCCESS);
logger.info("Sent email as a result of receiving {}", new Object[]{flowFile});

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

/**
 * Get all the recipient addresses for the message.
 * Extracts the TO, CC, BCC, and NEWSGROUPS recipients.
 *
 * @return          array of Address objects
 * @exception       MessagingException for failures
 * @see        javax.mail.Message.RecipientType#TO
 * @see        javax.mail.Message.RecipientType#CC
 * @see        javax.mail.Message.RecipientType#BCC
 * @see        javax.mail.internet.MimeMessage.RecipientType#NEWSGROUPS
 */
public Address[] getAllRecipients() throws MessagingException {
Address[] all = super.getAllRecipients();
Address[] ng = getRecipients(RecipientType.NEWSGROUPS);
if (ng == null)
  return all;		// the common case
if (all == null)
  return ng;		// a rare case
Address[] addresses = new Address[all.length + ng.length];
System.arraycopy(all, 0, addresses, 0, all.length);
System.arraycopy(ng, 0, addresses, all.length, ng.length);
return addresses;
}

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

/**
 * Get all the recipient addresses for the message.
 * Extracts the TO, CC, BCC, and NEWSGROUPS recipients.
 *
 * @return          array of Address objects
 * @exception       MessagingException for failures
 * @see        javax.mail.Message.RecipientType#TO
 * @see        javax.mail.Message.RecipientType#CC
 * @see        javax.mail.Message.RecipientType#BCC
 * @see        javax.mail.internet.MimeMessage.RecipientType#NEWSGROUPS
 */
@Override
public Address[] getAllRecipients() throws MessagingException {
Address[] all = super.getAllRecipients();
Address[] ng = getRecipients(RecipientType.NEWSGROUPS);
if (ng == null)
  return all;		// the common case
if (all == null)
  return ng;		// a rare case
Address[] addresses = new Address[all.length + ng.length];
System.arraycopy(all, 0, addresses, 0, all.length);
System.arraycopy(ng, 0, addresses, all.length, ng.length);
return addresses;
}

代码示例来源:origin: stackoverflow.com

Transport t = session.getTransport();
t.connect();
try {
 for(Message m : messages) {
  m.saveChanges();
  t.sendMessage(m, m.getAllRecipients());
 }
} finally {
 t.close();
}

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

/**
 * Send a message.  The message will be sent to all recipient
 * addresses specified in the message (as returned from the
 * <code>Message</code> method <code>getAllRecipients</code>).
 * The <code>send</code> method calls the <code>saveChanges</code>
 * method on the message before sending it. <p>
 *
 * Use the specified user name and password to authenticate to
 * the mail server.
 *
 * @param    msg    the message to send
 * @param    user    the user name
 * @param    password this user's password
 * @exception    SendFailedException if the message could not
 *            be sent to some or any of the recipients.
 * @exception    MessagingException for other failures
 * @see        Message#saveChanges
 * @see             #send(Message)
 * @see        javax.mail.SendFailedException
 * @since        JavaMail 1.5
 */
public static void send(Message msg,
  String user, String password) throws MessagingException {
msg.saveChanges();
send0(msg, msg.getAllRecipients(), user, password);
}

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

/**
 * Send a message.  The message will be sent to all recipient
 * addresses specified in the message (as returned from the
 * <code>Message</code> method <code>getAllRecipients</code>).
 * The <code>send</code> method calls the <code>saveChanges</code>
 * method on the message before sending it. <p>
 *
 * Use the specified user name and password to authenticate to
 * the mail server.
 *
 * @param    msg    the message to send
 * @param    user    the user name
 * @param    password this user's password
 * @exception    SendFailedException if the message could not
 *            be sent to some or any of the recipients.
 * @exception    MessagingException for other failures
 * @see        Message#saveChanges
 * @see             #send(Message)
 * @see        javax.mail.SendFailedException
 * @since        JavaMail 1.5
 */
public static void send(Message msg,
  String user, String password) throws MessagingException {
msg.saveChanges();
send0(msg, msg.getAllRecipients(), user, password);
}

代码示例来源: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: webx/citrus

/** 发送一个email。 */
public void send(Message message, MailTransportHandler handler) throws MailException {
  boolean autoClose = false;
  setHandler(handler);
  if (!isConnected()) {
    autoClose = true;
    connect();
  }
  try {
    message.setSentDate(new Date());
    if (getHandler() != null) {
      getHandler().processMessage(message);
    }
    message.saveChanges();
    Address[] recipients = message.getAllRecipients();
    if (isEmptyArray(recipients)) {
      throw new MailException("No recipient was specified in mail");
    }
    transport.sendMessage(message, recipients);
  } catch (MessagingException me) {
    throw new MailException("Could not send message", me);
  } finally {
    if (autoClose) {
      close();
    }
  }
}

代码示例来源:origin: webx/citrus

/** 发送一个email。 */
public void send(Message message, MailTransportHandler handler) throws MailException {
  boolean autoClose = false;
  setHandler(handler);
  if (!isConnected()) {
    autoClose = true;
    connect();
  }
  try {
    message.setSentDate(new Date());
    if (getHandler() != null) {
      getHandler().processMessage(message);
    }
    message.saveChanges();
    Address[] recipients = message.getAllRecipients();
    if (isEmptyArray(recipients)) {
      throw new MailException("No recipient was specified in mail");
    }
    transport.sendMessage(message, recipients);
  } catch (MessagingException me) {
    throw new MailException("Could not send message", me);
  } finally {
    if (autoClose) {
      close();
    }
  }
}

相关文章

微信公众号

最新文章

更多