1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.mail.javamail;
  17. import javax.mail.internet.MimeMessage;
  18. import org.springframework.mail.MailException;
  19. import org.springframework.mail.MailSender;
  20. /**
  21. * Extended MailSender interface for JavaMail, supporting MIME messages both as
  22. * direct arguments and via preparation callbacks.
  23. *
  24. * <p>Not as easy to test as a plain MailSender, but still rather easy compared
  25. * to full JavaMail code: Just let createMimeMessage return a plain MimeMessage
  26. * created with a Session.getInstance (empty properties) call, and check
  27. * the given messages in your mock implementations of the various send methods.
  28. *
  29. * <p>The recommended way of using this class is the MimeMessagePreparator
  30. * mechanism, possibly using a MimeMessageHelper for populating the message.
  31. * See MimeMessageHelper's javadoc for an example.
  32. *
  33. * @author Juergen Hoeller
  34. * @since 07.10.2003
  35. * @see JavaMailSenderImpl
  36. * @see MimeMessagePreparator
  37. * @see MimeMessageHelper
  38. */
  39. public interface JavaMailSender extends MailSender {
  40. /**
  41. * Create a new JavaMail MimeMessage for the underlying JavaMail Session
  42. * of this sender. Needs to be called to create MimeMessage instances
  43. * that can be prepared by the client and passed to send(MimeMessage).
  44. * @return the new MimeMessage instance
  45. * @see #send(MimeMessage)
  46. * @see #send(MimeMessage[])
  47. */
  48. MimeMessage createMimeMessage();
  49. /**
  50. * Send the given JavaMail MIME message.
  51. * The message needs to have been created with createMimeMessage.
  52. * @param mimeMessage message to send
  53. * @throws MailException in case of message, authentication or send errors
  54. * @see #createMimeMessage
  55. */
  56. void send(MimeMessage mimeMessage) throws MailException;
  57. /**
  58. * Send the given array of JavaMail MIME messages in batch.
  59. * The messages need to have been created with createMimeMessage.
  60. * @param mimeMessages messages to send
  61. * @throws MailException in case of message, authentication or send errors
  62. * @see #createMimeMessage
  63. */
  64. void send(MimeMessage[] mimeMessages) throws MailException;
  65. /**
  66. * Send the JavaMail MIME message prepared by the given MimeMessagePreparator.
  67. * Alternative way to prepare MimeMessage instances, instead of createMimeMessage
  68. * and send(MimeMessage) calls. Takes care of proper exception conversion.
  69. * @param mimeMessagePreparator the preparator to use
  70. * @throws MailException in case of message, authentication or send errors
  71. */
  72. void send(MimeMessagePreparator mimeMessagePreparator) throws MailException;
  73. /**
  74. * Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.
  75. * Alternative way to prepare MimeMessage instances, instead of createMimeMessage
  76. * and send(MimeMessage[]) calls. Takes care of proper exception conversion.
  77. * @param mimeMessagePreparators the preparator to use
  78. * @throws MailException in case of message, authentication or send errors
  79. */
  80. void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException;
  81. }