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

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

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

Message.setRecipients介绍

[英]Set the recipient addresses. All addresses of the specified type are replaced by the addresses parameter.
[中]设置收件人地址。指定类型的所有地址都将替换为addresses参数。

代码示例

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

  1. /**
  2. * Address message.
  3. * @param msg message, may not be null.
  4. * @throws MessagingException thrown if error addressing message.
  5. * @since 1.2.14
  6. */
  7. protected void addressMessage(final Message msg) throws MessagingException {
  8. if (from != null) {
  9. msg.setFrom(getAddress(from));
  10. } else {
  11. msg.setFrom();
  12. }
  13. //Add ReplyTo addresses if defined.
  14. if (replyTo != null && replyTo.length() > 0) {
  15. msg.setReplyTo(parseAddress(replyTo));
  16. }
  17. if (to != null && to.length() > 0) {
  18. msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
  19. }
  20. //Add CC receipients if defined.
  21. if (cc != null && cc.length() > 0) {
  22. msg.setRecipients(Message.RecipientType.CC, parseAddress(cc));
  23. }
  24. //Add BCC receipients if defined.
  25. if (bcc != null && bcc.length() > 0) {
  26. msg.setRecipients(Message.RecipientType.BCC, parseAddress(bcc));
  27. }
  28. }

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

  1. addressTo[i] = new InternetAddress( strArrRecipients[i] );
  2. msg.setRecipients( Message.RecipientType.TO, addressTo );

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

  1. message.setRecipients(Message.RecipientType.TO,
  2. InternetAddress.parse("to_email_address@domain.com"));
  3. message.setSubject("Testing Subject");

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

  1. message.setRecipients(Message.RecipientType.TO,
  2. InternetAddress.parse(creds.getTo()));
  3. message.setSubject("Sending message using Programmatic JavaMail " + Calendar.getInstance().getTime());

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

  1. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(creds.getTo()));
  2. message.setSubject("Sending message using Annotated JavaMail "
  3. + Calendar.getInstance().getTime());

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

  1. addressTo[i] = new InternetAddress( strArrRecipients[i] );
  2. msg.setRecipients( Message.RecipientType.TO, addressTo );

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

  1. m.setRecipients(Message.RecipientType.TO, new Address[0]);
  2. m.setRecipients(Message.RecipientType.CC, new Address[0]);
  3. m.setRecipients(Message.RecipientType.BCC, new Address[0]);

代码示例来源:origin: JpressProjects/jpress

  1. @Override
  2. public void send(Email email) {
  3. if (enable == false) {
  4. //do nothing
  5. return;
  6. }
  7. Message message = createMessage();
  8. try {
  9. message.setSubject(email.getSubject());
  10. message.setContent(email.getContent(), "text/html;charset=utf-8");
  11. message.setRecipients(Message.RecipientType.TO, toAddress(email.getTo()));
  12. message.setRecipients(Message.RecipientType.CC, toAddress(email.getCc()));
  13. Transport.send(message);
  14. } catch (MessagingException e) {
  15. logger.error("SimpleEmailSender send error", e);
  16. }
  17. }
  18. }

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

  1. final InternetAddress[] toAddresses = InternetAddress.parse(toAddress, false);
  2. final Message msg = new MimeMessage(getSession());
  3. msg.setRecipients(Message.RecipientType.TO, toAddresses);
  4. msg.setSubject(subject);
  5. msg.setSentDate(new Date());

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

  1. msg.setRecipients( Message.RecipientType.TO, address );
  2. msg.setRecipients( Message.RecipientType.CC, addressCc );
  3. msg.setRecipients( Message.RecipientType.BCC, addressBCc );

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

  1. @Override
  2. public void notify(final NotificationContext context, final NotificationType notificationType, final String subject, final String messageText) throws NotificationFailedException {
  3. final Properties properties = getMailProperties(context);
  4. final Session mailSession = createMailSession(properties);
  5. final Message message = new MimeMessage(mailSession);
  6. try {
  7. message.setFrom(InternetAddress.parse(context.getProperty(FROM).evaluateAttributeExpressions().getValue())[0]);
  8. final InternetAddress[] toAddresses = toInetAddresses(context.getProperty(TO).evaluateAttributeExpressions().getValue());
  9. message.setRecipients(RecipientType.TO, toAddresses);
  10. final InternetAddress[] ccAddresses = toInetAddresses(context.getProperty(CC).evaluateAttributeExpressions().getValue());
  11. message.setRecipients(RecipientType.CC, ccAddresses);
  12. final InternetAddress[] bccAddresses = toInetAddresses(context.getProperty(BCC).evaluateAttributeExpressions().getValue());
  13. message.setRecipients(RecipientType.BCC, bccAddresses);
  14. message.setHeader("X-Mailer", context.getProperty(HEADER_XMAILER).evaluateAttributeExpressions().getValue());
  15. message.setSubject(subject);
  16. final String contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
  17. message.setContent(messageText, contentType);
  18. message.setSentDate(new Date());
  19. Transport.send(message);
  20. } catch (final ProcessException | MessagingException e) {
  21. throw new NotificationFailedException("Failed to send E-mail Notification", e);
  22. }
  23. }

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

  1. address[i] = new InternetAddress( destinations[i] );
  2. msg.setRecipients( Message.RecipientType.TO, address );
  3. msg.setRecipients( Message.RecipientType.CC, addressCc );
  4. msg.setRecipients( Message.RecipientType.BCC, addressBCc );

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

  1. message.setRecipients(RecipientType.TO, toInetAddresses(context, flowFile, TO));
  2. message.setRecipients(RecipientType.CC, toInetAddresses(context, flowFile, CC));
  3. message.setRecipients(RecipientType.BCC, toInetAddresses(context, flowFile, BCC));

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

  1. /**
  2. * Set the recipient address. All addresses of the specified
  3. * type are replaced by the address parameter. <p>
  4. *
  5. * The default implementation uses the <code>setRecipients</code> method.
  6. *
  7. * @param type the recipient type
  8. * @param address the address
  9. * @exception IllegalWriteException if the underlying
  10. * implementation does not support modification
  11. * of existing values
  12. * @exception MessagingException for other failures
  13. */
  14. public void setRecipient(RecipientType type, Address address)
  15. throws MessagingException {
  16. if (address == null)
  17. setRecipients(type, null);
  18. else {
  19. Address[] a = new Address[1];
  20. a[0] = address;
  21. setRecipients(type, a);
  22. }
  23. }

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

  1. /**
  2. * Set the recipient address. All addresses of the specified
  3. * type are replaced by the address parameter. <p>
  4. *
  5. * The default implementation uses the <code>setRecipients</code> method.
  6. *
  7. * @param type the recipient type
  8. * @param address the address
  9. * @exception IllegalWriteException if the underlying
  10. * implementation does not support modification
  11. * of existing values
  12. * @exception MessagingException for other failures
  13. */
  14. public void setRecipient(RecipientType type, Address address)
  15. throws MessagingException {
  16. if (address == null)
  17. setRecipients(type, null);
  18. else {
  19. Address[] a = new Address[1];
  20. a[0] = address;
  21. setRecipients(type, a);
  22. }
  23. }

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

  1. Properties properties = System.getProperties();
  2. properties.put("mail.smtp.host", server);
  3. properties.put("mail.smtp.port", "" + port);
  4. Session session = Session.getInstance(properties);
  5. Transport transport = session.getTransport("smtp");
  6. transport.connect(server, username, password);
  7. for (int i = 0; i < count; i++) {
  8. Message message = new MimeMessage(session);
  9. message.setFrom(new InternetAddress(from));
  10. InternetAddress[] address = {new InternetAddress(to)};
  11. message.setRecipients(Message.RecipientType.TO, address);
  12. message.setSubject(subject + "JavaMail API");
  13. message.setSentDate(new Date());
  14. setHTMLContent(message);
  15. message.saveChanges();
  16. transport.sendMessage(message, address);
  17. }
  18. transport.close();

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

  1. /**
  2. * Address message.
  3. * @param msg message, may not be null.
  4. * @throws MessagingException thrown if error addressing message.
  5. * @since 1.2.14
  6. */
  7. protected void addressMessage(final Message msg) throws MessagingException {
  8. if (from != null) {
  9. msg.setFrom(getAddress(from));
  10. } else {
  11. msg.setFrom();
  12. }
  13. //Add ReplyTo addresses if defined.
  14. if (replyTo != null && replyTo.length() > 0) {
  15. msg.setReplyTo(parseAddress(replyTo));
  16. }
  17. if (to != null && to.length() > 0) {
  18. msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
  19. }
  20. //Add CC receipients if defined.
  21. if (cc != null && cc.length() > 0) {
  22. msg.setRecipients(Message.RecipientType.CC, parseAddress(cc));
  23. }
  24. //Add BCC receipients if defined.
  25. if (bcc != null && bcc.length() > 0) {
  26. msg.setRecipients(Message.RecipientType.BCC, parseAddress(bcc));
  27. }
  28. }

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

  1. /**
  2. * Sets the recipient for the given message.
  3. * @param msg the message.
  4. * @param key the key to search in the session.
  5. * @param type the recipient type.
  6. * @return true if the key was contained in the session.
  7. */
  8. private boolean setRecipient(final Message msg,
  9. final String key, final Message.RecipientType type) {
  10. boolean containsKey;
  11. final String value = getSession(msg).getProperty(key);
  12. containsKey = value != null;
  13. if (!isEmpty(value)) {
  14. try {
  15. final Address[] address = InternetAddress.parse(value, false);
  16. if (address.length > 0) {
  17. msg.setRecipients(type, address);
  18. }
  19. } catch (final MessagingException ME) {
  20. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  21. }
  22. }
  23. return containsKey;
  24. }

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

  1. /**
  2. * Sets the recipient for the given message.
  3. * @param msg the message.
  4. * @param key the key to search in the session.
  5. * @param type the recipient type.
  6. * @return true if the key was contained in the session.
  7. */
  8. private boolean setRecipient(final Message msg,
  9. final String key, final Message.RecipientType type) {
  10. boolean containsKey;
  11. final String value = getSession(msg).getProperty(key);
  12. containsKey = value != null;
  13. if (!isEmpty(value)) {
  14. try {
  15. final Address[] address = InternetAddress.parse(value, false);
  16. if (address.length > 0) {
  17. msg.setRecipients(type, address);
  18. }
  19. } catch (final MessagingException ME) {
  20. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  21. }
  22. }
  23. return containsKey;
  24. }

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

  1. /**
  2. * Computes the default to-address if none was specified. This can
  3. * fail if the local address can't be computed.
  4. * @param msg the message
  5. * @param type the recipient type.
  6. * @since JavaMail 1.5.0
  7. */
  8. private void setDefaultRecipient(final Message msg,
  9. final Message.RecipientType type) {
  10. try {
  11. Address a = InternetAddress.getLocalAddress(getSession(msg));
  12. if (a != null) {
  13. msg.setRecipient(type, a);
  14. } else {
  15. final MimeMessage m = new MimeMessage(getSession(msg));
  16. m.setFrom(); //Should throw an exception with a cause.
  17. Address[] from = m.getFrom();
  18. if (from.length > 0) {
  19. msg.setRecipients(type, from);
  20. } else {
  21. throw new MessagingException("No local address.");
  22. }
  23. }
  24. } catch (MessagingException | RuntimeException ME) {
  25. reportError("Unable to compute a default recipient.",
  26. ME, ErrorManager.FORMAT_FAILURE);
  27. }
  28. }

相关文章