`
gyl868
  • 浏览: 168426 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JavaMailSender 发邮件

    博客分类:
  • java
阅读更多
public class SendMailer {
 public static void main(String[] args) {
	 ApplicationContext context = new FileSystemXmlApplicationContext("src/mailsender.xml");
	  JavaMailSenderImpl mailsender = (JavaMailSenderImpl)context.getBean("mailsender");
	  System.out.println("|-username = "+mailsender.getUsername());
	  SimpleMailMessage msg = new SimpleMailMessage();
	  mailsender.getSession().getProperties().put("mail.smtp.auth", "true");
	  msg.setFrom("gyl868@163.com");
	  msg.setSubject("gmail测试邮件!");
	  msg.setText("邮件内容!无上瑜伽");
	  msg.setTo("24158944@qq.com");
	  mailsender.send(msg);
}
}



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
    default-autowire="byName" default-lazy-init="false">
<bean id="mailsender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
  <property name="host">
   <value>smtp.163.com</value>
  </property>
  <property name="username">
   <value>gyl868</value>
  </property>
     <property name="password">
   <value>111111</value>
  </property>
 </bean>
 </beans>


需要导入的包:spring.jar activation.jar  log4j.jar  commons-logging.jar  mail.jar
http://wbzboy.iteye.com/?page=2&show_full=true
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics