端认证设置
sender.setJavaMailProperties(props);
return sender;
}
}
三.bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mailSender" class="com.heyang.tool.mailsender.MailSenderImpl" singleton="false">
<property name="userName" value="XXXXXXXXXX"/>
<property name="password" value="XXXXXXXX"/>
<property name="stmpServer" value="smtp.163.com"/>
<property name="senderEmailAddr" value="XXXX@XXX.CCC"/>
</bean>
</beans>
四.使用示例
package com.heyang.util;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.heyang.tool.mailsender.BaseMailSender;
import com.heyang.tool.mailsender.MailSenderImpl;
/** *//**
* 异步邮件发送实用类(使用Spring的邮件发送形式)
* @author: 何杨(heyang78@gmail.com)
* @date: 2008-8-6-下午02:43:22
*/
public final class MailUtil {
/** *//**
* 发送邮件
* @param emailAddr:收信人邮件地址
* @param mailTitle:邮件标题
* @param mailConcept:邮件内容
*/
public static void sendMail(final String emailAddr, final String mailTitle,
final String mailConcept) {
Runnable thread=new Runnable(){
public void run(){
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
BaseMailSender sender=(MailSenderImpl)context.getBean("mailSender");
sender.sendMail(emailAddr, mailTitle, mailConcept);
}
};
new Thread(thread).start();
}
/** *//**
* 向系统维护者发送邮件
* @param mailTitle
* @param mailConcept
*/
public static void sendMailToSupporters(final String mailTitle,
final String mailConcept){
Runnable thread=new Runnable(){
public void run(){
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
SupportTeam supportTeam=(SupportTeam)context.getBean("supportTeam");
BaseMailSender sender=(MailSenderImpl)context.getBean("mailSender");
List<String> mails=supportTeam.getSupporterEmails();
for(String mailAddr:mails){
sender.sendMail(mailAddr, mailTitle, mailConcept);
}
}
};
new Thread(thread).start();
}
/** *//**
* 测试邮件发送
* @param args
*/
public static void main(String[] args){
MailUtil.sendMailToSupporters("title_spring", "concept_spring&q
|