001/*
002 * Copyright 2012-2018 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 *      http://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.boot.autoconfigure.mail;
018
019import javax.activation.MimeType;
020import javax.mail.internet.MimeMessage;
021
022import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
023import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
024import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
025import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
026import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
027import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration.MailSenderCondition;
028import org.springframework.boot.context.properties.EnableConfigurationProperties;
029import org.springframework.context.annotation.Conditional;
030import org.springframework.context.annotation.Configuration;
031import org.springframework.context.annotation.Import;
032import org.springframework.mail.MailSender;
033
034/**
035 * {@link EnableAutoConfiguration Auto configuration} for email support.
036 *
037 * @author Oliver Gierke
038 * @author Stephane Nicoll
039 * @author EddĂș MelĂ©ndez
040 * @since 1.2.0
041 */
042@Configuration
043@ConditionalOnClass({ MimeMessage.class, MimeType.class, MailSender.class })
044@ConditionalOnMissingBean(MailSender.class)
045@Conditional(MailSenderCondition.class)
046@EnableConfigurationProperties(MailProperties.class)
047@Import({ MailSenderJndiConfiguration.class, MailSenderPropertiesConfiguration.class })
048public class MailSenderAutoConfiguration {
049
050        /**
051         * Condition to trigger the creation of a {@link MailSender}. This kicks in if either
052         * the host or jndi name property is set.
053         */
054        static class MailSenderCondition extends AnyNestedCondition {
055
056                MailSenderCondition() {
057                        super(ConfigurationPhase.PARSE_CONFIGURATION);
058                }
059
060                @ConditionalOnProperty(prefix = "spring.mail", name = "host")
061                static class HostProperty {
062
063                }
064
065                @ConditionalOnProperty(prefix = "spring.mail", name = "jndi-name")
066                static class JndiNameProperty {
067
068                }
069
070        }
071
072}