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

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

本文整理了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

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

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

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

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

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

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

  1. @Override
  2. public void sendMessage(Message message, Address[] addresses) throws MessagingException {
  3. if ("fail".equals(message.getSubject())) {
  4. throw new MessagingException("failed");
  5. }
  6. if (addresses == null || (message.getAllRecipients() == null ? addresses.length > 0 :
  7. !ObjectUtils.nullSafeEquals(addresses, message.getAllRecipients()))) {
  8. throw new MessagingException("addresses not correct");
  9. }
  10. if (message.getSentDate() == null) {
  11. throw new MessagingException("No sentDate specified");
  12. }
  13. if (message.getSubject() != null && message.getSubject().contains("custom")) {
  14. assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate());
  15. }
  16. this.sentMessages.add(message);
  17. }
  18. }

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

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

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

  1. SendRawEmailResult resp = this.emailService.sendRawEmail(req);
  2. lastMessageId = resp.getMessageId();
  3. sent = m.getAllRecipients();
  4. unsent = new Address[0];
  5. invalid = new Address[0];
  6. } catch (Exception e) {
  7. sent = new Address[0];
  8. unsent = m.getAllRecipients();
  9. invalid = new Address[0];
  10. super.notifyTransportListeners(

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Get all the recipient addresses for the message.
  3. * Extracts the TO, CC, BCC, and NEWSGROUPS recipients.
  4. *
  5. * @return array of Address objects
  6. * @exception MessagingException for failures
  7. * @see javax.mail.Message.RecipientType#TO
  8. * @see javax.mail.Message.RecipientType#CC
  9. * @see javax.mail.Message.RecipientType#BCC
  10. * @see javax.mail.internet.MimeMessage.RecipientType#NEWSGROUPS
  11. */
  12. public Address[] getAllRecipients() throws MessagingException {
  13. Address[] all = super.getAllRecipients();
  14. Address[] ng = getRecipients(RecipientType.NEWSGROUPS);
  15. if (ng == null)
  16. return all; // the common case
  17. if (all == null)
  18. return ng; // a rare case
  19. Address[] addresses = new Address[all.length + ng.length];
  20. System.arraycopy(all, 0, addresses, 0, all.length);
  21. System.arraycopy(ng, 0, addresses, all.length, ng.length);
  22. return addresses;
  23. }

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

  1. /**
  2. * Get all the recipient addresses for the message.
  3. * Extracts the TO, CC, BCC, and NEWSGROUPS recipients.
  4. *
  5. * @return array of Address objects
  6. * @exception MessagingException for failures
  7. * @see javax.mail.Message.RecipientType#TO
  8. * @see javax.mail.Message.RecipientType#CC
  9. * @see javax.mail.Message.RecipientType#BCC
  10. * @see javax.mail.internet.MimeMessage.RecipientType#NEWSGROUPS
  11. */
  12. @Override
  13. public Address[] getAllRecipients() throws MessagingException {
  14. Address[] all = super.getAllRecipients();
  15. Address[] ng = getRecipients(RecipientType.NEWSGROUPS);
  16. if (ng == null)
  17. return all; // the common case
  18. if (all == null)
  19. return ng; // a rare case
  20. Address[] addresses = new Address[all.length + ng.length];
  21. System.arraycopy(all, 0, addresses, 0, all.length);
  22. System.arraycopy(ng, 0, addresses, all.length, ng.length);
  23. return addresses;
  24. }

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

  1. Transport t = session.getTransport();
  2. t.connect();
  3. try {
  4. for(Message m : messages) {
  5. m.saveChanges();
  6. t.sendMessage(m, m.getAllRecipients());
  7. }
  8. } finally {
  9. t.close();
  10. }

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

  1. /**
  2. * Send a message. The message will be sent to all recipient
  3. * addresses specified in the message (as returned from the
  4. * <code>Message</code> method <code>getAllRecipients</code>).
  5. * The <code>send</code> method calls the <code>saveChanges</code>
  6. * method on the message before sending it. <p>
  7. *
  8. * Use the specified user name and password to authenticate to
  9. * the mail server.
  10. *
  11. * @param msg the message to send
  12. * @param user the user name
  13. * @param password this user's password
  14. * @exception SendFailedException if the message could not
  15. * be sent to some or any of the recipients.
  16. * @exception MessagingException for other failures
  17. * @see Message#saveChanges
  18. * @see #send(Message)
  19. * @see javax.mail.SendFailedException
  20. * @since JavaMail 1.5
  21. */
  22. public static void send(Message msg,
  23. String user, String password) throws MessagingException {
  24. msg.saveChanges();
  25. send0(msg, msg.getAllRecipients(), user, password);
  26. }

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

  1. /**
  2. * Send a message. The message will be sent to all recipient
  3. * addresses specified in the message (as returned from the
  4. * <code>Message</code> method <code>getAllRecipients</code>).
  5. * The <code>send</code> method calls the <code>saveChanges</code>
  6. * method on the message before sending it. <p>
  7. *
  8. * Use the specified user name and password to authenticate to
  9. * the mail server.
  10. *
  11. * @param msg the message to send
  12. * @param user the user name
  13. * @param password this user's password
  14. * @exception SendFailedException if the message could not
  15. * be sent to some or any of the recipients.
  16. * @exception MessagingException for other failures
  17. * @see Message#saveChanges
  18. * @see #send(Message)
  19. * @see javax.mail.SendFailedException
  20. * @since JavaMail 1.5
  21. */
  22. public static void send(Message msg,
  23. String user, String password) throws MessagingException {
  24. msg.saveChanges();
  25. send0(msg, msg.getAllRecipients(), user, password);
  26. }

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

  1. @Test
  2. void testFromToBccCc() throws MessagingException {
  3. final Email email = Email.create()
  4. .from(FROM_EXAMPLE_COM)
  5. .to(TO1_EXAMPLE_COM).to("Major Tom", "to2@example.com")
  6. .cc(CC1_EXAMPLE_COM).cc("Major Carson", "cc2@example.com")
  7. .bcc("Major Ben", "bcc1@example.com").bcc(BCC2_EXAMPLE_COM);
  8. final Message message = createMessage(email);
  9. assertEquals(1, message.getFrom().length);
  10. assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
  11. assertEquals(6, message.getAllRecipients().length);
  12. assertEquals(2, message.getRecipients(RecipientType.TO).length);
  13. assertEquals(TO1_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
  14. assertEquals("Major Tom <to2@example.com>", message.getRecipients(RecipientType.TO)[1].toString());
  15. assertEquals(2, message.getRecipients(RecipientType.CC).length);
  16. assertEquals(CC1_EXAMPLE_COM, message.getRecipients(RecipientType.CC)[0].toString());
  17. assertEquals("Major Carson <cc2@example.com>", message.getRecipients(RecipientType.CC)[1].toString());
  18. assertEquals(2, message.getRecipients(RecipientType.BCC).length);
  19. assertEquals("Major Ben <bcc1@example.com>", message.getRecipients(RecipientType.BCC)[0].toString());
  20. assertEquals(BCC2_EXAMPLE_COM, message.getRecipients(RecipientType.BCC)[1].toString());
  21. }

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

  1. /** 发送一个email。 */
  2. public void send(Message message, MailTransportHandler handler) throws MailException {
  3. boolean autoClose = false;
  4. setHandler(handler);
  5. if (!isConnected()) {
  6. autoClose = true;
  7. connect();
  8. }
  9. try {
  10. message.setSentDate(new Date());
  11. if (getHandler() != null) {
  12. getHandler().processMessage(message);
  13. }
  14. message.saveChanges();
  15. Address[] recipients = message.getAllRecipients();
  16. if (isEmptyArray(recipients)) {
  17. throw new MailException("No recipient was specified in mail");
  18. }
  19. transport.sendMessage(message, recipients);
  20. } catch (MessagingException me) {
  21. throw new MailException("Could not send message", me);
  22. } finally {
  23. if (autoClose) {
  24. close();
  25. }
  26. }
  27. }

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

  1. /** 发送一个email。 */
  2. public void send(Message message, MailTransportHandler handler) throws MailException {
  3. boolean autoClose = false;
  4. setHandler(handler);
  5. if (!isConnected()) {
  6. autoClose = true;
  7. connect();
  8. }
  9. try {
  10. message.setSentDate(new Date());
  11. if (getHandler() != null) {
  12. getHandler().processMessage(message);
  13. }
  14. message.saveChanges();
  15. Address[] recipients = message.getAllRecipients();
  16. if (isEmptyArray(recipients)) {
  17. throw new MailException("No recipient was specified in mail");
  18. }
  19. transport.sendMessage(message, recipients);
  20. } catch (MessagingException me) {
  21. throw new MailException("Could not send message", me);
  22. } finally {
  23. if (autoClose) {
  24. close();
  25. }
  26. }
  27. }

相关文章