锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲AV噜噜一区二区三区,亚洲成年网站在线观看,亚洲人成亚洲精品http://www.tkk7.com/gen-sky/category/40681.html鍕ゆ濄佽皚璦銆佹厧琛屻佸帤縐佽杽鍙?/description>zh-cnThu, 28 Feb 2013 15:34:25 GMTThu, 28 Feb 2013 15:34:25 GMT60spring3 email 鍙戦佷唬鐮?http://www.tkk7.com/gen-sky/articles/spring3_email.html鏄熸湡浜?/dc:creator>鏄熸湡浜?/author>Thu, 28 Feb 2013 10:08:00 GMThttp://www.tkk7.com/gen-sky/articles/spring3_email.htmlhttp://www.tkk7.com/gen-sky/comments/395869.htmlhttp://www.tkk7.com/gen-sky/articles/spring3_email.html#Feedback0http://www.tkk7.com/gen-sky/comments/commentRss/395869.htmlhttp://www.tkk7.com/gen-sky/services/trackbacks/395869.html閰嶇疆浠g爜閮借秴榪囦簡涓諱唬鐮?nbsp;
涓嶈繃閰嶇疆浠g爜閮芥槸甯哥敤鐨勶紝鐣欑潃澶囦喚鍚с?br />mavne pox 閰嶇疆



 1 <dependency>
 2             <groupId>javax.mail</groupId>
 3             <artifactId>mail</artifactId>
 4             <version>1.4</version>
 5         </dependency>
 6     <dependency>
 7             <groupId>org.springframework</groupId>
 8             <artifactId>spring-beans</artifactId>
 9             <version>${org.springframework.version}</version>
10         </dependency>

spring-xml 閰嶇疆
<bean id="propertyConfigurer"
        class
="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:cfg/config.properties</value>
            </list>
        </property>
    </bean>

    <bean id="mail"
        class
="org.springframework.mail.javamail.JavaMailSenderImpl">
        <!-- SMTP鍙戦侀偖浠剁殑鏈嶅姟鍣ㄧ殑IP鍜岀鍙?nbsp;-->
        <property name="host" value="${mail.host}" />
        <property name="port" value="${mail.port}" />

        <!-- 鐧婚檰SMTP閭歡鍙戦佹湇鍔″櫒鐨勭敤鎴峰悕鍜屽瘑鐮?nbsp;-->
        <property name="username" value="${mail.username}" />
        <property name="password" value="${mail.password}" />

        <!-- 鑾峰緱閭歡浼?xì)璇濆睘鎬?楠岃瘉鐧誨綍閭歡鏈嶅姟鍣ㄦ槸鍚︽垚鍔?/span>-->
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="prop">true</prop>
                <prop key="mail.smtp.timeout">25000</prop>
            </props>
        </property>
    </bean>


properties 鏂囦歡閰嶇疆

mail.host=smtp.yeah.net
mail.port=25
mail.username=****
mail.password=****
java 綾誨垎鍒負(fù)錛?br />
import org.springframework.context.support.AbstractApplicationContext;

import com.ms.AppContext;

public class SpringHelper {

    /**
     * 鑾峰彇spring渚濊禆娉ㄥ叆鐨勫璞?br />     * 
     * 
@param name
     * 
@return Object Bean
     
*/
    public static Object getBean(String name) {
        AbstractApplicationContext ctx = AppContext.getInstance()
                .getAppContext();

        return ctx.getBean(name);
    }
}


import java.util.ArrayList;
import java.util.List;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppContext {
    private static AppContext instance;

    private volatile AbstractApplicationContext appContext;

    public synchronized static AppContext getInstance() {
        if (instance == null) {
            instance = new AppContext();
        }

        return instance;
    }

    private AppContext() {
        List<String> list = new ArrayList<String>();
        list.add("/cfg/*.xml");

        String ss[] = list.toArray(new String[] {});
        for (int i = 0; i < ss.length; i++) {
            System.out.println("ss[" + i + "]" + ss[i]);

        }

        this.appContext = new ClassPathXmlApplicationContext(ss);
    }

    public AbstractApplicationContext getAppContext() {
        return appContext;
    }
}



import java.io.File;
import java.util.Date;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import com.ms.SpringHelper;
import com.util.Configuration;

/**
 * 鍙戦侀偖浠?nbsp;宸ュ叿
 * 
 * 
@author 
 * @file com.ms.util --- SentMaileUtil.java
 * 
@version 2013-2-28 -涓嬪崍03:42:03
 
*/
public class SendMaileUtil {
    private static JavaMailSender javaMailSender;

    private static Logger logger = Logger.getLogger(SendMaileUtil.class);

    private static JavaMailSender newIntstance() {
        if (javaMailSender == null) {
            javaMailSender = (JavaMailSender) SpringHelper.getBean("mail");
        }
        return javaMailSender;
    }

    /**
     * 鍙戦佺殑鏂囨湰嫻嬭瘯閭歡
     * 
     * 
@param to
     * 
@param mailSubject
     * 
@param mailBody
     
*/
    public static void sendTextMaile(String to, String mailSubject,
            String mailBody) {
        if (logger.isDebugEnabled())
            logger.debug("鍑嗗鍙戦佹枃鏈艦寮忕殑閭歡");
        SimpleMailMessage mail1 = new SimpleMailMessage();
        String from = Configuration.getValue("mail.form");
        mail1.setFrom(from);// 鍙戦佷漢鍚嶇墖
        mail1.setTo(to);// 鏀朵歡浜洪偖綆?/span>
        mail1.setSubject(mailSubject);// 閭歡涓婚
        mail1.setSentDate(new Date());// 閭歡鍙戦佹椂闂?/span>
        mail1.setText(mailBody);

        // 緹ゅ彂
        SimpleMailMessage[] mailMessages = { mail1 };
        newIntstance().send(mailMessages);

        if (logger.isDebugEnabled())
            logger.debug("鏂囨湰褰㈠紡鐨勯偖浠跺彂閫佹垚鍔燂紒錛侊紒");
    }

    /**
     * 浠?nbsp;HTML鑴氭湰褰㈠紡閭歡鍙戦?br />     * 
     * 
@param to
     * 
@param mailSubject
     * 
@param mailBody
     
*/
    public static void sendHtmlMail(String to, String mailSubject,
            String mailBody) {
        JavaMailSender mailSender = newIntstance();
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        try {
            if (logger.isDebugEnabled())
                logger.debug("HTML鑴氭湰褰㈠紡閭歡姝e湪鍙戦?img src="http://www.tkk7.com/Images/dot.gif" alt="" />");
            // 璁劇疆utf-8鎴朑BK緙栫爜錛屽惁鍒欓偖浠朵細(xì)鏈変貢鐮?/span>
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true,
                    "UTF-8");
            // 璁劇疆鍙戦佷漢鍚嶇墖
            String from = Configuration.getValue("mail.form");
            helper.setFrom(from);
            // 璁劇疆鏀朵歡浜哄悕鐗囧拰鍦板潃
            helper.setTo(new InternetAddress("\""
                    + MimeUtility.encodeText("gamil閭") + "\" <" + to + ">"));// 鍙戦佽?br />            // 閭歡鍙戦佹椂闂?/span>
            helper.setSentDate(new Date());
            // 璁劇疆鍥炲鍦板潃
            helper.setReplyTo(new InternetAddress(from));
            // 璁劇疆鎶勯佺殑鍚嶇墖鍜屽湴鍧
            
// helper.setCc(InternetAddress.parse(MimeUtility.encodeText("鎶勯佷漢001")
            
// + " <@163.com>," + MimeUtility.encodeText("鎶勯佷漢002")
            
// + " <@foxmail.com>"));
            
// 涓婚
            helper.setSubject("轂旐敿鞏胳壗");
            // 閭歡鍐呭錛屾敞鎰忓姞鍙傛暟true錛岃〃紺哄惎鐢╤tml鏍煎紡
            helper
                    .setText(
                            "<html><head></head><body><h1>hello!!鎴戞槸涔斿竷鏂?lt;/h1></body></html>",
                            true);
            // 鍙戦?/span>
            mailSender.send(mimeMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (logger.isDebugEnabled())
            logger.debug("HTML鑴氭湰褰㈠紡閭歡鍙戦佹垚鍔燂紒錛侊紒");
    }

    /**
     * 浠ラ檮浠剁殑褰㈠紡鍙戦侀偖浠?br />     * 
     * 
@param to
     *            鏀朵歡浜篹amil 鍦板潃
     * 
@param toName
     *            鏀朵歡浜烘樀縐?br />     * 
@param mailSubject
     *            涓婚
     * 
@param mailBody
     *            鍐呭浣?br />     * 
@param files
     *            闄勪歡
     
*/
    public static void sendFileMail(String to, String toName,
            String mailSubject, String mailBody, File[] files) {
        JavaMailSender mailSender = newIntstance();
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        try {
            if (logger.isDebugEnabled())
                logger.debug("甯﹂檮浠跺拰鍥劇墖鐨勯偖浠舵鍦ㄥ彂閫?img src="http://www.tkk7.com/Images/dot.gif" alt="" />");

            // 璁劇疆utf-8鎴朑BK緙栫爜錛屽惁鍒欓偖浠朵細(xì)鏈変貢鐮?/span>
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true,
                    "UTF-8");
            // 璁劇疆鍙戦佷漢鍚嶇墖
            String from = Configuration.getValue("mail.form");
            helper.setFrom(from);

            // 璁劇疆鏀朵歡浜洪偖綆?/span>
            helper.setTo(new InternetAddress("\""
                    + MimeUtility.encodeText(toName) + "\" <" + to + ">"));

            // 璁劇疆鍥炲鍦板潃
            
// helper.setReplyTo(new InternetAddress("@qq.com"));

            
// 璁劇疆鏀朵歡浜烘妱閫佺殑鍚嶇墖鍜屽湴鍧(鐩稿綋浜庣兢鍙戜簡)
            
// helper.setCc(InternetAddress.parse(MimeUtility.encodeText("閭001")
            
// + " <@163.com>," + MimeUtility.encodeText("閭002")
            
// + " <@foxmail.com>"));

            
// 涓婚
            helper.setSubject(mailSubject);
            // 閭歡鍐呭錛屾敞鎰忓姞鍙傛暟true錛岃〃紺哄惎鐢╤tml鏍煎紡
            helper.setText(mailBody);
            if (files != null && files.length > 0) {
                for (int i = 0; i < files.length; i++)
                    // 鍔犲叆闄勪歡
                    helper.addAttachment(MimeUtility.encodeText(files[i]
                            .getName()), files[i]);
            }
            // 鍔犲叆鎻掑浘
            helper.addInline(MimeUtility.encodeText("pic01"), new File(
                    "c:/temp/2dd24be463.jpg"));
            // 鍙戦?/span>
            mailSender.send(mimeMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("甯﹂檮浠跺拰鍥劇墖鐨勯偖浠跺彂閫佹垚鍔燂紒錛侊紒");
        }
    }

    public static void main(String[] args) {
        PropertyConfigurator.configure(ClassLoader
                .getSystemResource("cfg/log4j.properties"));

        SendMaileUtil.sendTextMaile("*****@gmail.com",
                "Spring Mail 嫻嬭瘯閭歡", "Hello,Boy,This is my Spring Mail,鍝堝搱錛侊紒");

        SendMaileUtil.sendHtmlMail("*****@gmail.com", nullnull);
        File file = new File("c:/temp");
        File[] fs = file.listFiles();

        SendMaileUtil.sendFileMail("******@yeah.net", "鏄電О", "涓婚", "鍐呭",
                fs);

    }
}









import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.pub.Forward;

/**
 * 璇誨彇properties鏂囦歡
 * 
@author 
 *
 
*/
public class Configuration
{
    private static Properties propertie;
    private InputStream in;
    private static Configuration config = new Configuration();
    
    /**
     * 鍒濆鍖朇onfiguration綾?br />     
*/
    public Configuration()
    {
        propertie = new Properties();
        try {
//            System.out.println(System.getProperty("user.dir"));
//            inputFile = new FileInputStream("cfg/config.properties");
            in =  ClassLoader.getSystemResourceAsStream("cfg/config.properties");
            propertie.load(in);
            in.close();
        } catch (FileNotFoundException ex) {
            System.out.println("璇誨彇灞炴ф枃浠?-->澶辮觸錛? 鍘熷洜錛氭枃浠惰礬寰勯敊璇垨鑰呮枃浠朵笉瀛樺湪");
            ex.printStackTrace();
        } catch (IOException ex) {
            System.out.println("瑁呰澆鏂囦歡--->澶辮觸!");
            ex.printStackTrace();
        }        
    }
    

    
    /**
     * 閲嶈澆鍑芥暟錛屽緱鍒発ey鐨勫?br />     * 
@param key 鍙栧緱鍏跺肩殑閿?br />     * @return key鐨勫?br />     */
    public static  String getValue(String key)
    {
        if(propertie.containsKey(key)){
            String value = propertie.getProperty(key);//寰楀埌鏌愪竴灞炴х殑鍊?/span>
            return value;
        }
        else 
            return "";
    }//end getValue()

    


    
    public static void main(String[] args)
    {

        System.out.println(Configuration.getValue("aaa"));
        System.out.println(System.getProperty("user.dir"));


        
    }//end main()
    
}//end class ReadConfigInfo





























]]>
主站蜘蛛池模板: 毛片免费在线视频| 亚洲一区二区三区免费视频| 亚洲欧洲免费无码| 中国人xxxxx69免费视频| 精品久久香蕉国产线看观看亚洲| 男女污污污超污视频免费在线看| 国产精品久久香蕉免费播放| 亚洲AV无码国产精品色| 在线观看特色大片免费视频| 亚洲精品电影在线| 24小时日本电影免费看| 亚洲欧洲精品久久| 亚洲免费中文字幕| 亚洲另类精品xxxx人妖| 91免费播放人人爽人人快乐| 中文字幕精品三区无码亚洲 | 久久久久亚洲AV无码专区网站| 婷婷亚洲综合一区二区| 男人的天堂亚洲一区二区三区| 国产成人精品日本亚洲专| 91香蕉视频免费| 久久久久久亚洲av无码蜜芽| 可以免费观看一级毛片黄a| 永久免费无码日韩视频| 好看的电影网站亚洲一区| 麻豆成人久久精品二区三区免费 | 亚洲免费视频播放| 亚洲人成色在线观看| 免费精品国产自产拍观看| 黄色一级免费网站| 亚洲国产精品成人精品无码区| 免费A级毛片无码专区| 日本亚洲精品色婷婷在线影院 | 可以免费看的卡一卡二| 亚洲精品无播放器在线播放 | 亚洲人成影院77777| 国产在线观看免费不卡| 中文字幕免费人成乱码中国| 亚洲男人的天堂在线播放| 免费观看美女裸体网站| 一级毛片人与动免费观看|