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

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

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

Message.setReplyTo介绍

[英]Set the addresses to which replies should be directed. (Normally only a single address will be specified.) Not all message types allow this to be specified separately from the sender of the message.

The default implementation provided here just throws the MethodNotSupportedException.
[中]设置回复应指向的地址。(通常只指定一个地址。)并非所有邮件类型都允许将其与邮件的发件人分开指定。
这里提供的默认实现只是抛出MethodNotSupportedException。

代码示例

代码示例来源: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. msg.setReplyTo( address );

代码示例来源:origin: kiegroup/jbpm

  1. User user = TaskModelProvider.getFactory().newUser();
  2. ((InternalOrganizationalEntity) user).setId(header.getReplyTo());
  3. msg.setReplyTo( new InternetAddress[] {
  4. new InternetAddress(userInfo.getEmailForEntity(user))});
  5. } else if (mailSession.getProperty("mail.replyto") != null) {
  6. msg.setReplyTo( new InternetAddress[] { new InternetAddress(mailSession.getProperty("mail.replyto"))});

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

  1. address[i] = new InternetAddress( reply_Address_List[i] );
  2. msg.setReplyTo( address );

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

  1. /**
  2. * Sets reply-to address header.
  3. * @param msg the target message.
  4. */
  5. private void setReplyTo(final Message msg) {
  6. final String reply = getSession(msg).getProperty("mail.reply.to");
  7. if (!isEmpty(reply)) {
  8. try {
  9. final Address[] address = InternetAddress.parse(reply, false);
  10. if (address.length > 0) {
  11. msg.setReplyTo(address);
  12. }
  13. } catch (final MessagingException ME) {
  14. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  15. }
  16. }
  17. }

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

  1. /**
  2. * Sets reply-to address header.
  3. * @param msg the target message.
  4. */
  5. private void setReplyTo(final Message msg) {
  6. final String reply = getSession(msg).getProperty("mail.reply.to");
  7. if (!isEmpty(reply)) {
  8. try {
  9. final Address[] address = InternetAddress.parse(reply, false);
  10. if (address.length > 0) {
  11. msg.setReplyTo(address);
  12. }
  13. } catch (final MessagingException ME) {
  14. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  15. }
  16. }
  17. }

代码示例来源: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: google/mail-importer

  1. @Override
  2. public void setReplyTo(Address[] addresses) throws RuntimeMessagingException {
  3. try {
  4. delegate.setReplyTo(addresses);
  5. } catch (MessagingException e) {
  6. throw new RuntimeMessagingException(e);
  7. }
  8. }

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

  1. private void setReplyTo(final Message msg, final Properties props) {
  2. final String reply = props.getProperty("mail.reply.to");
  3. if (reply != null && reply.length() > 0) {
  4. try {
  5. final Address[] address = InternetAddress.parse(reply, false);
  6. if (address != null && address.length > 0) {
  7. msg.setReplyTo(address);
  8. }
  9. } catch (final MessagingException ME) {
  10. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  11. }
  12. }
  13. }

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

  1. public String sendMail(String from, String to, String replyTo, String subject, String message) {
  2. String output=null;
  3. Properties props = new Properties();
  4. Session session = Session.getDefaultInstance(props, null);
  5. try {
  6. Message msg = new MimeMessage(session);
  7. msg.setFrom(new InternetAddress(from, "Gmail.com Admin"));
  8. msg.addRecipient(Message.RecipientType.TO,
  9. new InternetAddress(to, "Mr. User"));
  10. msg.setSubject(subject);
  11. msg.setText(message);
  12. msg.setReplyTo(new InternetAddress[]{new InternetAddress(replyTo)});
  13. Transport.send(msg);
  14. } catch (Exception e) {
  15. output=e.toString();
  16. }
  17. return output;
  18. }

代码示例来源:origin: org.codemonkey.simplejavamail/simple-java-mail

  1. /**
  2. * Fills the {@link Message} instance with reply-to address.
  3. *
  4. * @param email The message in which the recipients are defined.
  5. * @param message The javax message that needs to be filled with reply-to address.
  6. * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
  7. * @throws MessagingException See {@link Message#setReplyTo(Address[])}
  8. */
  9. private static void setReplyTo(final Email email, final Message message)
  10. throws UnsupportedEncodingException, MessagingException {
  11. final Recipient replyToRecipient = email.getReplyToRecipient();
  12. if (replyToRecipient != null) {
  13. InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(), CHARACTER_ENCODING);
  14. message.setReplyTo(new Address[] { replyToAddress });
  15. }
  16. }

代码示例来源:origin: aseldawy/spatialhadoop2

  1. private void sendFailureEmail(Exception e) throws AddressException, MessagingException, UnsupportedEncodingException {
  2. Properties props = new Properties(MAIL_PROPERTIES);
  3. Session mailSession = Session.getInstance(props,
  4. new javax.mail.Authenticator() {
  5. protected PasswordAuthentication getPasswordAuthentication() {
  6. return new PasswordAuthentication(username, password);
  7. }
  8. });
  9. Message message = new MimeMessage(mailSession);
  10. InternetAddress requesterAddress = new InternetAddress(email, requesterName);
  11. message.setFrom(new InternetAddress(from, "SHAHED Team"));
  12. message.addRecipient(RecipientType.TO, requesterAddress);
  13. InternetAddress adminAddress = new InternetAddress("eldawy@cs.umn.edu", "Ahmed Eldawy");
  14. message.addRecipient(RecipientType.BCC, adminAddress);
  15. message.setSubject("Confirmation: Your request has failed");
  16. message.setText("Dear "+requesterName+",\n"+
  17. "Unfortunately there was an internal error while processing your request.\n"+
  18. e.getMessage() + "\n" +
  19. "Sorry for inconvenience. \n\n Shahed team");
  20. message.setReplyTo(new InternetAddress[] {new InternetAddress(from, "SHAHED Team")});
  21. Transport.send(message, message.getAllRecipients());
  22. LOG.info("Message sent successfully to '"+requesterAddress+"'");
  23. }

代码示例来源:origin: org.simplejavamail/simple-java-mail

  1. /**
  2. * Fills the {@link Message} instance with reply-to address.
  3. *
  4. * @param email The message in which the recipients are defined.
  5. * @param message The javax message that needs to be filled with reply-to address.
  6. * @throws UnsupportedEncodingException See {@link InternetAddress#InternetAddress(String, String)}.
  7. * @throws MessagingException See {@link Message#setReplyTo(Address[])}
  8. */
  9. private static void setReplyTo(final Email email, final Message message)
  10. throws UnsupportedEncodingException, MessagingException {
  11. final Recipient replyToRecipient = email.getReplyToRecipient();
  12. if (replyToRecipient != null) {
  13. final InternetAddress replyToAddress = new InternetAddress(replyToRecipient.getAddress(), replyToRecipient.getName(),
  14. CHARACTER_ENCODING);
  15. message.setReplyTo(new Address[] { replyToAddress });
  16. }
  17. }

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

  1. /**
  2. * Sets reply-to address header.
  3. * @param msg the target message.
  4. */
  5. private void setReplyTo(final Message msg) {
  6. final String reply = getSession(msg).getProperty("mail.reply.to");
  7. if (!isEmpty(reply)) {
  8. try {
  9. final Address[] address = InternetAddress.parse(reply, false);
  10. if (address.length > 0) {
  11. msg.setReplyTo(address);
  12. }
  13. } catch (final MessagingException ME) {
  14. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  15. }
  16. }
  17. }

代码示例来源:origin: org.glassfish.metro/webservices-extra

  1. /**
  2. * Sets reply-to address header.
  3. * @param msg the target message.
  4. */
  5. private void setReplyTo(final Message msg) {
  6. final String reply = getSession(msg).getProperty("mail.reply.to");
  7. if (!isEmpty(reply)) {
  8. try {
  9. final Address[] address = InternetAddress.parse(reply, false);
  10. if (address.length > 0) {
  11. msg.setReplyTo(address);
  12. }
  13. } catch (final MessagingException ME) {
  14. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  15. }
  16. }
  17. }

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

  1. /**
  2. * Sets reply-to address header.
  3. * @param msg the target message.
  4. */
  5. private void setReplyTo(final Message msg) {
  6. final String reply = getSession(msg).getProperty("mail.reply.to");
  7. if (!isEmpty(reply)) {
  8. try {
  9. final Address[] address = InternetAddress.parse(reply, false);
  10. if (address.length > 0) {
  11. msg.setReplyTo(address);
  12. }
  13. } catch (final MessagingException ME) {
  14. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  15. }
  16. }
  17. }

代码示例来源:origin: jboss/jboss-javaee-specs

  1. /**
  2. * Sets reply-to address header.
  3. * @param msg the target message.
  4. */
  5. private void setReplyTo(final Message msg) {
  6. final String reply = getSession(msg).getProperty("mail.reply.to");
  7. if (!isEmpty(reply)) {
  8. try {
  9. final Address[] address = InternetAddress.parse(reply, false);
  10. if (address.length > 0) {
  11. msg.setReplyTo(address);
  12. }
  13. } catch (final MessagingException ME) {
  14. reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
  15. }
  16. }
  17. }

代码示例来源:origin: org.xbib.malva/malva

  1. public void send(String subject,
  2. Address from, Address[] replyTo,
  3. Address[] to, Address[] cc, Address[] bcc,
  4. Multipart multipart) throws Exception {
  5. WithContext<Object> action = ctx -> {
  6. Message message = new MimeMessage(ctx.session);
  7. message.setSentDate(new Date());
  8. message.setFrom(from);
  9. message.setSubject(subject);
  10. if (replyTo != null) {
  11. message.setReplyTo(replyTo);
  12. }
  13. message.setRecipients(Message.RecipientType.TO, to);
  14. if (cc != null) {
  15. message.setRecipients(Message.RecipientType.CC, cc);
  16. }
  17. if (bcc != null) {
  18. message.setRecipients(Message.RecipientType.BCC, bcc);
  19. }
  20. message.setContent(multipart);
  21. Transport.send(message);
  22. return null;
  23. };
  24. performWithContext(action);
  25. }

代码示例来源:origin: org.apache.log4j/com.springsource.org.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: com.impetus.fabric/fabric-jdbc-driver-shaded

  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. }

相关文章