/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.spring.mail;

import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * The Class MailUtilTest.
 * 
 * @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
 */
public class JavaMailSenderUtilTest{

    /** The context. */
    private ApplicationContext context;

    /** The mail util. */
    private JavaMailSenderUtil mailUtil;

    /**
     * Inits the.
     */
    @Before
    public void init(){
        context = new ClassPathXmlApplicationContext("classpath*:spring-mail.xml");
        mailUtil = context.getBean(JavaMailSenderUtil.class);
    }

    /**
     * Send email.
     */
    @Test
    public void sendEmail(){
        Map<String, Object> model = new HashMap<>();
        model.put("userName", "大关");
        model.put("email" + "Address", "woshidaguan@126.com");
        String[] mailTo = new String[] { "venusdrogon@163.com" };
        // String[] files = new String[] { "F:/Photo 照片/2012/else/120120A011.jpg", "F:/Photo 照片/2012/else/120127A001.jpg" };
        String vmfile = "com/guan/chapter19/email/welcome.vm";
        String subject = "欢迎您的加入";
        mailUtil.sendEmail(null, subject, vmfile, mailTo, null);
    }

    /**
     * Send.
     */
    @Test
    public void send(){
        String[] to = new String[] { "venusdrogon@163.com" };
        String subject = "欢迎您的加入暗示的发射点法";
        String text = "<span style='color:red'><br>鑫哥艾莉梅阿斯达萨</br></span>";
        mailUtil.send(to, subject, text, null);
    }

    /**
     * Send mail native.
     */
    @Test
    public void sendMailNative(){
        String[] to = new String[] { "venusdrogon@163.com" };
        String subject = "你好";
        String text = "<span style='color:red'><br>鑫哥 </br></span>";
        mailUtil.sendMailNative(to, subject, text, null);
    }
}

/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.spring.mail;

import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * The Class MailUtilTest.
 * 
 * @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
 */
public class JavaMailSenderUtilTest{

    /** The context. */
    private ApplicationContext    context;

    /** The mail util. */
    private JavaMailSenderUtil    mailUtil;

    private final static String[] to = new String[] { "venusdrogon@163.com" };

    /**
     * Inits the.
     */
    @Before
    public void init(){
        context = new ClassPathXmlApplicationContext("classpath*:spring-mail.xml");
        mailUtil = context.getBean(JavaMailSenderUtil.class);
    }

    /**
     * Send email.
     */
    @Test
    public void sendEmail(){
        Map<String, Object> model = new HashMap<>();
        model.put("userName", "大关");
        model.put("email" + "Address", "woshidaguan@126.com");
        // String[] files = new String[] { "F:/Photo 照片/2012/else/120120A011.jpg", "F:/Photo 照片/2012/else/120127A001.jpg" };
        String vmfile = "com/guan/chapter19/email/welcome.vm";
        String subject = "欢迎您的加入";
        mailUtil.sendEmail(null, subject, vmfile, to, null);
    }

    /**
     * Send.
     */
    @Test
    public void send(){
        String subject = "欢迎您的加入暗示的发射点法";
        String text = "<span style='color:red'><br>鑫哥艾莉梅阿斯达萨</br></span>";
        mailUtil.send(to, subject, text, null);
    }

    /**
     * Send mail native.
     */
    @Test
    public void sendMailNative(){

        String subject = "你好";
        String text = "<span style='color:red'><br>鑫哥 </br></span>";
        mailUtil.sendMailNative(to, subject, text, null);
    }
}

update email