javax.mail.internet.MimeMessage.reply()方法的使用及代码示例

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

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

MimeMessage.reply介绍

[英]Get a new Message suitable for a reply to this message. The new Message will have its attributes and headers set up appropriately. Note that this new message object will be empty, i.e., it will not have a "content". These will have to be suitably filled in by the client.

If replyToAll is set, the new Message will be addressed to all recipients of this message. Otherwise, the reply will be addressed to only the sender of this message (using the value of the getReplyTo method).

The "Subject" field is filled in with the original subject prefixed with "Re:" (unless it already starts with "Re:"). The "In-Reply-To" header is set in the new message if this message has a "Message-Id" header. The ANSWERED flag is set in this message. The current implementation also sets the "References" header in the new message to include the contents of the "References" header (or, if missing, the "In-Reply-To" header) in this message, plus the contents of the "Message-Id" header of this message, as described in RFC 2822.
[中]获取适合回复此邮件的新邮件。新消息将适当设置其属性和标题。请注意,这个新消息对象将是空的,也就是说,它将没有“内容”。这些必须由客户适当填写。
如果设置了replyToAll,新邮件将发送给此邮件的所有收件人。否则,回复将仅发送给此邮件的发件人(使用getReplyTo方法的值)。
“主题”字段用前缀为“Re:”的原始主题填充(除非它已经以“Re:”开头)。如果新邮件具有“邮件Id”标题,则在新邮件中设置“回复”标题。此消息中设置了ANSWERED标志。当前的实现还将新消息中的“References”头设置为包括该消息中的“References”头(或者,如果缺少,则包括“in Reply to”头)的内容,以及该消息的“message Id”头的内容,如RFC 2822所述。

代码示例

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

return reply(replyToAll, true);

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

return reply(replyToAll, true);

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

return reply(replyToAll, true);

代码示例来源:origin: javax.mail/javax.mail-api

return reply(replyToAll, true);

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

return reply(replyToAll, true);

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

return reply(replyToAll, true);

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

return reply(replyToAll, true);

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

return reply(replyToAll, true);

代码示例来源:origin: org.apache.james/james-server-core-library

/**
 * This does not need a writable message
 * @see javax.mail.Message#reply(boolean)
 */
public Message reply(boolean replyToAll) throws MessagingException {
  return getWrappedMessage().reply(replyToAll);
}

代码示例来源:origin: at.researchstudio.sat/won-bot

public WonMimeMessage createWelcomeMail(MimeMessage msgToRespondTo) throws IOException, MessagingException {
  VelocityContext velocityContext = new VelocityContext();
  putQuotedMail(velocityContext, msgToRespondTo);
  velocityContext.put("mailbotEmailAddress", sentFrom);
  velocityContext.put("mailbotName", sentFromName);
  StringWriter writer = new StringWriter();
  velocityEngine.getTemplate("mail-templates/welcome-mail.vm").merge(velocityContext, writer);
  MimeMessage answerMessage = (MimeMessage) msgToRespondTo.reply(false);
  answerMessage.setFrom(new InternetAddress(sentFrom, sentFromName));
  answerMessage.setText(writer.toString());
  WonMimeMessage wonAnswerMessage = new WonMimeMessage(answerMessage);
  wonAnswerMessage.updateMessageID();
  return wonAnswerMessage;
}

代码示例来源:origin: org.apache.james/james-server-mailets

public MimeMessage execute(Session session, MimeMessage message) throws MessagingException {
  MimeMessage reply = (MimeMessage) message.reply(false);
  reply.setContent(computeMultiPartResponse(session, message));
  if (null == message.getAllRecipients() || 0 >= message.getAllRecipients().length) {
    throw new MessagingException("Message has no recipients");
  } else {
    Address from = message.getAllRecipients()[0];
    reply.setFrom(from);
  }
  reply.saveChanges();
  return reply;
}

代码示例来源:origin: org.apache.james/james-server-mailets

public VacationReply build() throws MessagingException {
  Preconditions.checkState(eitherReasonOrMime());
  ActionUtils.detectAndHandleLocalLooping(originalMail, context, "vacation");
  MimeMessage reply = (MimeMessage) originalMail.getMessage().reply(false);
  reply.setSubject(generateNotificationSubject());
  reply.setContent(generateNotificationContent());
  return new VacationReply(retrieveOriginalSender(), ImmutableList.of(originalMail.getMaybeSender().get()), reply);
}

代码示例来源:origin: org.apache.james/apache-standard-mailets

/**
 * Sends a message back to the sender indicating what time the server thinks it is.
 *
 * @param mail the mail being processed
 *
 * @throws javax.mail.MessagingException if an error is encountered while formulating the reply message
 */
public void service(Mail mail) throws javax.mail.MessagingException {
  MimeMessage response = (MimeMessage)mail.getMessage().reply(false);
  response.setSubject("The time is now...");
  StringBuffer textBuffer =
    new StringBuffer(128)
        .append("This mail server thinks it's ")
        .append((new java.util.Date()).toString())
        .append(".");
  response.setText(textBuffer.toString());
  // Someone manually checking the server time by hand may send
  // an formatted message, lacking From and To headers.  If the
  // response fields are null, try setting them from the SMTP
  // MAIL FROM/RCPT TO commands used to send the inquiry.
  if (response.getFrom() == null) {
    response.setFrom(((MailAddress)mail.getRecipients().iterator().next()).toInternetAddress());
  }
  if (response.getAllRecipients() == null) {
    response.setRecipients(MimeMessage.RecipientType.TO, mail.getSender().toString());
  }
  response.saveChanges();
  getMailetContext().sendMail(response);
}

代码示例来源:origin: org.apache.james/james-server-mailetcontainer-library

/**
 * Generates a bounce mail that is a bounce of the original message.
 * 
 * @param bounceText
 *            the text to be prepended to the message to describe the bounce
 *            condition
 * 
 * @return the bounce mail
 * 
 * @throws MessagingException
 *             if the bounce mail could not be created
 */
private MailImpl rawBounce(Mail mail, String bounceText) throws MessagingException {
  // This sends a message to the james component that is a bounce of the
  // sent message
  MimeMessage original = mail.getMessage();
  MimeMessage reply = (MimeMessage) original.reply(false);
  reply.setSubject("Re: " + original.getSubject());
  reply.setSentDate(new Date());
  Collection<MailAddress> recipients = new HashSet<MailAddress>();
  recipients.add(mail.getSender());
  InternetAddress addr[] = { new InternetAddress(mail.getSender().toString()) };
  reply.setRecipients(Message.RecipientType.TO, addr);
  reply.setFrom(new InternetAddress(mail.getRecipients().iterator().next().toString()));
  reply.setText(bounceText);
  reply.setHeader(RFC2822Headers.MESSAGE_ID, "replyTo-" + mail.getName());
  return new MailImpl("replyTo-" + mail.getName(), new MailAddress(mail.getRecipients().iterator().next().toString()), recipients, reply);
}

代码示例来源:origin: at.researchstudio.sat/won-bot

private WonMimeMessage generateWonMimeMessage(
 MimeMessage msgToRespondTo, Template template, VelocityContext velocityContext, URI remoteNeedUri)
 throws MessagingException, UnsupportedEncodingException {
  Dataset remoteNeedRDF = eventListenerContext.getLinkedDataSource().getDataForResource(remoteNeedUri);
  DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(remoteNeedRDF);
  MimeMessage answerMessage = (MimeMessage) msgToRespondTo.reply(false);
  answerMessage.setFrom(new InternetAddress(sentFrom, sentFromName));
  answerMessage.setText("");
  answerMessage.setSubject(answerMessage.getSubject() + " <-> " + StringUtils.trim(needModelWrapper.getSomeTitleFromIsOrAll("en","de")));
  //We need to create an instance of our own MimeMessage Implementation in order to have the Unique Message Id set before sending
  WonMimeMessage wonAnswerMessage = new WonMimeMessage(answerMessage);
  wonAnswerMessage.updateMessageID();
  String messageId = wonAnswerMessage.getMessageID();
  // put variables (e.g. Message-Id) for the footer into the context and create mail body using the template
  putCommandFooter(velocityContext, wonAnswerMessage);
  StringWriter writer = new StringWriter();
  template.merge(velocityContext, writer);
  answerMessage.setText(writer.toString());
  // create a new won mime message with the right body and message id set
  wonAnswerMessage = new WonMimeMessage(answerMessage);
  wonAnswerMessage.setMessageId(messageId);
  return wonAnswerMessage;
}

代码示例来源:origin: org.apache.james/james-server-mailetcontainer-camel

/**
 * Generates a bounce mail that is a bounce of the original message.
 *
 * @param bounceText the text to be prepended to the message to describe the bounce
 *                   condition
 * @return the bounce mail
 * @throws MessagingException if the bounce mail could not be created
 */
private MailImpl rawBounce(Mail mail, String bounceText) throws MessagingException {
  Preconditions.checkArgument(mail.hasSender(), "Mail should have a sender");
  // This sends a message to the james component that is a bounce of the sent message
  MimeMessage original = mail.getMessage();
  MimeMessage reply = (MimeMessage) original.reply(false);
  reply.setSubject("Re: " + original.getSubject());
  reply.setSentDate(new Date());
  Collection<MailAddress> recipients = mail.getMaybeSender().asList();
  MailAddress sender = mail.getMaybeSender().get();
  reply.setRecipient(Message.RecipientType.TO, new InternetAddress(mail.getMaybeSender().asString()));
  reply.setFrom(new InternetAddress(mail.getRecipients().iterator().next().toString()));
  reply.setText(bounceText);
  reply.setHeader(RFC2822Headers.MESSAGE_ID, "replyTo-" + mail.getName());
  return new MailImpl("replyTo-" + mail.getName(), sender, recipients, reply);
}

代码示例来源:origin: org.apache.james/apache-jsieve-mailet

MimeMessage reply = (MimeMessage) aMail.getMessage().reply(false);
reply.setFrom(soleRecipient.toInternetAddress());
reply.setContent(multiPart);

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

final MimeMessage replyMessage;
try {
  replyMessage = (MimeMessage) emailMessage.reply(repyToAll);
  replyMessage.setText("ignore");
  replyMessage.setFrom("ignore@ignore.ignore");

代码示例来源:origin: org.apache.james/james-server-jmap

private MimeMessage generateMimeMessage(MimeMessageBodyGenerator mimeMessageBodyGenerator) throws MessagingException {
    MimeMessage reply = (MimeMessage) originalMail.getMessage().reply(NOT_REPLY_TO_ALL);
    vacation.getSubject().ifPresent(Throwing.consumer(subjectString -> reply.setHeader("subject", subjectString)));
    reply.setHeader(FROM_HEADER, mailRecipient.toString());
    reply.setHeader(TO_HEADER, originalMail.getMaybeSender().get().asString());
    reply.setHeader(AutomaticallySentMailDetector.AUTO_SUBMITTED_HEADER, AutomaticallySentMailDetector.AUTO_REPLIED_VALUE);
    return mimeMessageBodyGenerator.from(reply, vacation.getTextBody(), vacation.getHtmlBody());
  }
}

代码示例来源:origin: org.apache.james/james-server-mailets

MimeMessage reply = (MimeMessage) aMail.getMessage().reply(false);
reply.setFrom(soleRecipient.toInternetAddress());
reply.setContent(multipart);

相关文章

MimeMessage类方法