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

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

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

Message.saveChanges介绍

[英]Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder. (Some implementations may save the changes immediately.) Update any header fields to be consistent with the changed message contents. If any part of a message's headers or contents are changed, saveChanges must be called to ensure that those changes are permanent. If saveChanges is not called, any such modifications may or may not be saved, depending on the message store and folder implementation.

Messages obtained from folders opened READ_ONLY should not be modified and saveChanges should not be called on such messages.
[中]如果邮件包含在文件夹中,请在包含文件夹关闭时将对此邮件所做的任何更改保存到邮件存储中。(某些实现可能会立即保存更改。)更新任何标题字段,使其与更改的邮件内容一致。如果邮件标题或内容的任何部分发生更改,则必须调用saveChanges以确保这些更改是永久性的。如果未调用saveChanges,则任何此类修改都可能保存,也可能不保存,具体取决于消息存储和文件夹实现。
从以只读方式打开的文件夹中获取的邮件不应被修改,也不应对此类邮件调用saveChanges。

代码示例

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

tr.connect(session.getProperty("mail." + protocol + ".user"),
      session.getProperty("mail." + protocol + ".password"));
  msg.saveChanges(); // don't forget this
  tr.sendMessage(msg, msg.getAllRecipients());
} finally {

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

/**
 * Send the message to the specified addresses, ignoring any
 * recipients specified in the message itself. The
 * <code>send</code> method calls the <code>saveChanges</code>
 * method on the message before sending it. <p>
 *
 * @param    msg    the message to send
 * @param    addresses the addresses to which to send the message
 * @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
 */
public static void send(Message msg, Address[] addresses) 
  throws MessagingException {
msg.saveChanges();
send0(msg, addresses, null, null);
}

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

/**
 * Send the message to the specified addresses, ignoring any
 * recipients specified in the message itself. The
 * <code>send</code> method calls the <code>saveChanges</code>
 * method on the message before sending it. <p>
 *
 * @param    msg    the message to send
 * @param    addresses the addresses to which to send the message
 * @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
 */
public static void send(Message msg, Address[] addresses) 
  throws MessagingException {
msg.saveChanges();
send0(msg, addresses, null, null);
}

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

/**
 * Send the message to the specified addresses, ignoring any
 * recipients specified in the message itself. 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    addresses the addresses to which to send the message
 * @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, Address[] addresses,
  String user, String password) throws MessagingException {
msg.saveChanges();
send0(msg, addresses, user, password);
}

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

/**
 * Send the message to the specified addresses, ignoring any
 * recipients specified in the message itself. 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    addresses the addresses to which to send the message
 * @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, Address[] addresses,
  String user, String password) throws MessagingException {
msg.saveChanges();
send0(msg, addresses, user, password);
}

代码示例来源: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: stackoverflow.com

Properties properties = System.getProperties();
 properties.put("mail.smtp.host", server);
 properties.put("mail.smtp.port", "" + port);
 Session session = Session.getInstance(properties);
 Transport transport = session.getTransport("smtp");
 transport.connect(server, username, password);
 for (int i = 0; i < count; i++) {
   Message message = new MimeMessage(session);
   message.setFrom(new InternetAddress(from));
   InternetAddress[] address = {new InternetAddress(to)};
   message.setRecipients(Message.RecipientType.TO, address);
   message.setSubject(subject + "JavaMail API");
   message.setSentDate(new Date());
   setHTMLContent(message);
   message.saveChanges();
   transport.sendMessage(message, address);
 }
 transport.close();

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

try {
  try {
    abort.saveChanges();
  } catch (final NullPointerException xferEncoding) {
      if (abort.getHeader(cte) == null) {
        abort.setHeader(cte, "base64");
        abort.saveChanges();
      } else {
        throw xferEncoding;

代码示例来源: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: 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: com.sun.mail/javax.mail

msg.saveChanges(); // do this first
send0(msg, msg.getAllRecipients(), null, null);

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

msg.saveChanges(); // do this first
send0(msg, msg.getAllRecipients(), null, null);

代码示例来源: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();
    }
  }
}

代码示例来源:origin: google/mail-importer

@Override
public void saveChanges() throws RuntimeMessagingException {
 try {
  delegate.saveChanges();
 } catch (MessagingException e) {
  throw new RuntimeMessagingException(e);
 }
}

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

// Create a email session
Session session = Session.getInstance(props);

// Create a new Message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setText(BODY);
msg.saveChanges();

// Reuse one Transport object for sending all your messages
// for better performance
Transport t = new AWSJavaMailTransport(session, null);
t.connect();
t.sendMessage(msg, null);

代码示例来源:origin: org.springframework.ws/spring-ws-support

@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
  Transport transport = null;
  try {
    responseMessage.setDataHandler(
        new DataHandler(new ByteArrayDataSource(responseContentType, responseBuffer.toByteArray())));
    transport = session.getTransport(transportUri);
    transport.connect();
    responseMessage.saveChanges();
    transport.sendMessage(responseMessage, responseMessage.getAllRecipients());
  }
  catch (MessagingException ex) {
    throw new MailTransportException(ex);
  }
  finally {
    MailTransportUtils.closeService(transport);
  }
}

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

/**
 * If the message is <code>format=flowed</code> 
 * set the encoded version as message content.
 */
public static void deflowMessage(Message m) throws MessagingException, IOException {
  ContentType ct = new ContentType(m.getContentType());
  String format = ct.getParameter("format");
  if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
    String delSp = ct.getParameter("delsp");
    String deflowed = deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
    
    ct.getParameterList().remove("format");
    ct.getParameterList().remove("delsp");
    
    if (ct.toString().contains("flowed")) {
      LOGGER.error("FlowedMessageUtils dind't remove the flowed correctly");
    }
    m.setContent(deflowed, ct.toString());
    m.saveChanges();
  }
}

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

/**
 * Encodes the message content (if text/plain).
 */
public static void flowMessage(Message m, boolean delSp, int width) throws MessagingException, IOException {
  ContentType ct = new ContentType(m.getContentType());
  if (!ct.getBaseType().equals("text/plain")) {
    return;
  }
  String format = ct.getParameter("format");
  String text = format != null && format.equals("flowed") ? deflow(m) : (String) m.getContent();
  String coded = flow(text, delSp, width);
  ct.setParameter("format", "flowed");
  if (delSp) {
    ct.setParameter("delsp", "yes");
  }
  m.setContent(coded, ct.toString());
  m.saveChanges();
}

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

private static void setContentFromPart(Message m, Part p, String newText, boolean setTextPlain) throws MessagingException, IOException {
  String contentType = p.getContentType();
  if (setTextPlain) {
    ContentType ct = new ContentType(contentType);
    ct.setPrimaryType("text");
    ct.setSubType("plain");
    contentType = ct.toString();
  }
  m.setContent(newText != null ? newText : p.getContent(), contentType);
  String[] h = p.getHeader("Content-Transfer-Encoding");
  if (h != null && h.length > 0) m.setHeader("Content-Transfer-Encoding", h[0]);
  m.saveChanges();
}

相关文章

微信公众号

最新文章

更多