必须添加的包commons-logging.jar,mail.jar,spring.jar
mailMessage.xml配置文件********************************

 xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation=" http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
 xmlns:aop=" http://www.springframework.org/schema/aop"
 xmlns:p=" http://www.springframework.org/schema/p">
 
 
 
  
   
    classpath:mail.properties
   

  

 

 
 
 
  
   
   ]]>
  

  
  
  
 

 
 
 
  
  
  
  
  
   
    
    true
    
    true
   

  

 

 
 
 
mail.properties************************
mail.host=smtp.163.com//走163发送协议
mail.username=xxxxxxxx//163邮箱名
mail.password=xxxxxxxx//163邮箱密码
[email protected]//发送者邮箱 这里就是163邮箱
[email protected]//接受者邮箱
 
测试文件***********************
package mail;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
public class SpringSimpleMailTest {
 public static void main(String[] args) {
  ApplicationContext actx = new ClassPathXmlApplicationContext(
    "mail/mailMessage.xml");
  MailSender ms = (MailSender) actx.getBean("mailSender");
  SimpleMailMessage smm = (SimpleMailMessage) actx.getBean("mailMessage");
  // 主题,内容
  smm.setSubject("你好");
  smm.setText("这个是一个通过Spring框架来发送邮件的小程序");
  ms.send(smm);
 }
}