001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.mail.javamail;
018
019import javax.mail.internet.MimeMessage;
020
021/**
022 * Callback interface for the preparation of JavaMail MIME messages.
023 *
024 * <p>The corresponding {@code send} methods of {@link JavaMailSender}
025 * will take care of the actual creation of a {@link MimeMessage} instance,
026 * and of proper exception conversion.
027 *
028 * <p>It is often convenient to use a {@link MimeMessageHelper} for populating
029 * the passed-in MimeMessage, in particular when working with attachments or
030 * special character encodings.
031 * See {@link MimeMessageHelper MimeMessageHelper's javadoc} for an example.
032 *
033 * @author Juergen Hoeller
034 * @since 07.10.2003
035 * @see JavaMailSender#send(MimeMessagePreparator)
036 * @see JavaMailSender#send(MimeMessagePreparator[])
037 * @see MimeMessageHelper
038 */
039public interface MimeMessagePreparator {
040
041        /**
042         * Prepare the given new MimeMessage instance.
043         * @param mimeMessage the message to prepare
044         * @throws javax.mail.MessagingException passing any exceptions thrown by MimeMessage
045         * methods through for automatic conversion to the MailException hierarchy
046         * @throws java.io.IOException passing any exceptions thrown by MimeMessage methods
047         * through for automatic conversion to the MailException hierarchy
048         * @throws Exception if mail preparation failed, for example when a
049         * Velocity template cannot be rendered for the mail text
050         */
051        void prepare(MimeMessage mimeMessage) throws Exception;
052
053}