com.badgersoft.nayifprocessor.config.MailConfig.java Source code

Java tutorial

Introduction

Here is the source code for com.badgersoft.nayifprocessor.config.MailConfig.java

Source

/*
   This file is part of the FUNcube Data Warehouse
       
   Copyright 2013,2014 (c) David A.Johnson, G4DPZ, AMSAT-UK
    
The FUNcube Data Warehouse is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
    
The FUNcube Data Warehouse is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with The FUNcube Data Warehouse.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.badgersoft.nayifprocessor.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.ui.velocity.VelocityEngineFactoryBean;

import java.util.Properties;

@Configuration
public class MailConfig {

    @Bean
    JavaMailSenderImpl mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

        mailSender.setHost("smtp.gmail.com");
        mailSender.setPort(587);
        mailSender.setUsername("dave@g4dpz.me.uk");
        mailSender.setPassword("H4les0wen1234!");

        Properties properties = new Properties();
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable", "true");

        mailSender.setJavaMailProperties(properties);

        return mailSender;
    }

    @Bean
    SimpleMailMessage alertMailMessage() {
        SimpleMailMessage alertMailMessage = new SimpleMailMessage();

        alertMailMessage.setFrom("dave@g4dpz.me.uk");
        alertMailMessage.setTo("operations@funcube.org.uk");
        alertMailMessage.setSubject("Alert - Exception occurred. Please investigate");

        return alertMailMessage;
    }

    @Bean
    VelocityEngineFactoryBean velocityEngine() {
        VelocityEngineFactoryBean velocityEngine = new VelocityEngineFactoryBean();

        //velocityEngine.setResourceLoaderPath("/velocity");

        Properties velocityProperties = new Properties();
        velocityProperties.put("input.encoding", "utf-8");
        velocityProperties.put("output.encoding", "utf-8");
        //velocityProperties.put("file.resource.loader.path", "//velocity");

        velocityEngine.setVelocityProperties(velocityProperties);

        return velocityEngine;
    }

}