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

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

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

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

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

  1. /**
  2. * Send the message to the specified addresses, ignoring any
  3. * recipients specified in the message itself. The
  4. * <code>send</code> method calls the <code>saveChanges</code>
  5. * method on the message before sending it. <p>
  6. *
  7. * @param msg the message to send
  8. * @param addresses the addresses to which to send the message
  9. * @exception SendFailedException if the message could not
  10. * be sent to some or any of the recipients.
  11. * @exception MessagingException for other failures
  12. * @see Message#saveChanges
  13. * @see #send(Message)
  14. * @see javax.mail.SendFailedException
  15. */
  16. public static void send(Message msg, Address[] addresses)
  17. throws MessagingException {
  18. msg.saveChanges();
  19. send0(msg, addresses, null, null);
  20. }

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

  1. /**
  2. * Send the message to the specified addresses, ignoring any
  3. * recipients specified in the message itself. The
  4. * <code>send</code> method calls the <code>saveChanges</code>
  5. * method on the message before sending it. <p>
  6. *
  7. * @param msg the message to send
  8. * @param addresses the addresses to which to send the message
  9. * @exception SendFailedException if the message could not
  10. * be sent to some or any of the recipients.
  11. * @exception MessagingException for other failures
  12. * @see Message#saveChanges
  13. * @see #send(Message)
  14. * @see javax.mail.SendFailedException
  15. */
  16. public static void send(Message msg, Address[] addresses)
  17. throws MessagingException {
  18. msg.saveChanges();
  19. send0(msg, addresses, null, null);
  20. }

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

  1. /**
  2. * Send the message to the specified addresses, ignoring any
  3. * recipients specified in the message itself. The
  4. * <code>send</code> method calls the <code>saveChanges</code>
  5. * method on the message before sending it. <p>
  6. *
  7. * Use the specified user name and password to authenticate to
  8. * the mail server.
  9. *
  10. * @param msg the message to send
  11. * @param addresses the addresses to which to send the message
  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, Address[] addresses,
  23. String user, String password) throws MessagingException {
  24. msg.saveChanges();
  25. send0(msg, addresses, user, password);
  26. }

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

  1. /**
  2. * Send the message to the specified addresses, ignoring any
  3. * recipients specified in the message itself. The
  4. * <code>send</code> method calls the <code>saveChanges</code>
  5. * method on the message before sending it. <p>
  6. *
  7. * Use the specified user name and password to authenticate to
  8. * the mail server.
  9. *
  10. * @param msg the message to send
  11. * @param addresses the addresses to which to send the message
  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, Address[] addresses,
  23. String user, String password) throws MessagingException {
  24. msg.saveChanges();
  25. send0(msg, addresses, user, password);
  26. }

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

  1. try {
  2. try {
  3. abort.saveChanges();
  4. } catch (final NullPointerException xferEncoding) {
  5. if (abort.getHeader(cte) == null) {
  6. abort.setHeader(cte, "base64");
  7. abort.saveChanges();
  8. } else {
  9. throw xferEncoding;

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

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

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

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

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

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

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

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

  1. // Create a email session
  2. Session session = Session.getInstance(props);
  3. // Create a new Message
  4. Message msg = new MimeMessage(session);
  5. msg.setFrom(new InternetAddress(FROM));
  6. msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
  7. msg.setSubject(SUBJECT);
  8. msg.setText(BODY);
  9. msg.saveChanges();
  10. // Reuse one Transport object for sending all your messages
  11. // for better performance
  12. Transport t = new AWSJavaMailTransport(session, null);
  13. t.connect();
  14. t.sendMessage(msg, null);

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

  1. @Override
  2. protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
  3. Transport transport = null;
  4. try {
  5. responseMessage.setDataHandler(
  6. new DataHandler(new ByteArrayDataSource(responseContentType, responseBuffer.toByteArray())));
  7. transport = session.getTransport(transportUri);
  8. transport.connect();
  9. responseMessage.saveChanges();
  10. transport.sendMessage(responseMessage, responseMessage.getAllRecipients());
  11. }
  12. catch (MessagingException ex) {
  13. throw new MailTransportException(ex);
  14. }
  15. finally {
  16. MailTransportUtils.closeService(transport);
  17. }
  18. }

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

  1. /**
  2. * If the message is <code>format=flowed</code>
  3. * set the encoded version as message content.
  4. */
  5. public static void deflowMessage(Message m) throws MessagingException, IOException {
  6. ContentType ct = new ContentType(m.getContentType());
  7. String format = ct.getParameter("format");
  8. if (ct.getBaseType().equals("text/plain") && format != null && format.equalsIgnoreCase("flowed")) {
  9. String delSp = ct.getParameter("delsp");
  10. String deflowed = deflow((String) m.getContent(), delSp != null && delSp.equalsIgnoreCase("yes"));
  11. ct.getParameterList().remove("format");
  12. ct.getParameterList().remove("delsp");
  13. if (ct.toString().contains("flowed")) {
  14. LOGGER.error("FlowedMessageUtils dind't remove the flowed correctly");
  15. }
  16. m.setContent(deflowed, ct.toString());
  17. m.saveChanges();
  18. }
  19. }

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

  1. /**
  2. * Encodes the message content (if text/plain).
  3. */
  4. public static void flowMessage(Message m, boolean delSp, int width) throws MessagingException, IOException {
  5. ContentType ct = new ContentType(m.getContentType());
  6. if (!ct.getBaseType().equals("text/plain")) {
  7. return;
  8. }
  9. String format = ct.getParameter("format");
  10. String text = format != null && format.equals("flowed") ? deflow(m) : (String) m.getContent();
  11. String coded = flow(text, delSp, width);
  12. ct.setParameter("format", "flowed");
  13. if (delSp) {
  14. ct.setParameter("delsp", "yes");
  15. }
  16. m.setContent(coded, ct.toString());
  17. m.saveChanges();
  18. }

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

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

相关文章