spring + mail
orderManagerImpl:
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
public class OrderManagerImpl implements OrderManager {
private MailSender mailSender;
private SimpleMailMessage templateMessage;
public void placeOrder() {
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
msg.setTo("330940840@qq.com");
msg.setText("my first test mail.");
//MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,true,"utf-8");
try {
this.mailSender.send(msg);
} catch (MailException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
/**
* Setter method for property <tt>mailSender</tt>.
*
* @param mailSender value to be assigned to property mailSender
*/
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
/**
* Setter method for property <tt>simpleMailMessage</tt>.
*
* @param simpleMailMessage value to be assigned to property simpleMailMessage
*/
public void setTemplateMessage(SimpleMailMessage templateMessage) {
this.templateMessage = templateMessage;
}
}
sendMailTest.java
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @author wb-yingpf
* @version $Id: SendMailTest.java, v 0.1 2012-6-11 下午03:05:45 wb-yingpf Exp $
*/
public class SendMailTest {
@Test
public void testSendMail() {
ApplicationContext ac = new ClassPathXmlApplicationContext("test.xml");
OrderManagerImpl orderManager = (OrderManagerImpl) ac.getBean("orderManager");
orderManager.placeOrder();
}
}
test.xml
<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:sofa="http://img.alipay.net/dtd/schema/service" xmlns:context="http://www.springframework.org/schema/context"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://img.alipay.net/dtd/schema/service http://img.alipay.net/dtd/schema/service/sofa-service.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd"
default-autowire="byName">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="defaultEncoding" value="utf-8"></property>
<property name="host" value="smtp.163.com"></property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
<property name="username" value="yingpengfei1215@163.com"></property>
<property name="password" value="*****"></property>
</bean>
<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value="yingpengfei1215@163.com"></property>
<property name="subject" value="yingpengfei1215@126.com"></property>
</bean>
<bean id="orderManager" class="com.alipay.OrderManagerImpl">
<property name="mailSender" ref="mailSender" />
<property name="templateMessage" ref="templateMessage" />
</bean>
</beans>
需要导入的jar包:
Spring-2.5.4.jar
junit-4.7.jar
commons-logging-1.1.1.jar
mail-1.4.jar
分享到:
相关推荐
spring.mail.default-encoding=UTF-8 #电子邮件地址 spring.mail.host=smtp.126.com #Application spring.application.name=SEND-MAIL #授权密码 spring.mail.password=password #邮箱服务器默认端口 spring.mail....
NULL 博文链接:https://bastengao.iteye.com/blog/1064392
maven配置了阿里云的仓库,不能下载spring-boot-starter-mail的依赖,从官网下载的,希望对有同样问题的小伙伴有用
引入加 spring-boot-starter-mail 依赖包: Spring Boot整合邮件发送并保存历史发送邮箱 2、配置文件 application.yml Spring Boot整合邮件发送并保存历史发送邮箱 注意:测试时需要将 spring.mail.username 和...
该项目基于Spring 3.1.3, Spring MVC, Hibernate 4.1.7, EhCache, Spring Data JPA 1.1.0, MySQL 5, Spring Security 3.1.3, Spring Mail, Recapcha等技术实现了网站注册、登录系统。项目包含了详尽的配置信息。 ...
spring-boot-mail:spring boot和邮件服务 spring-boot-mongodb:spring boot和mongodb的使用 spring-boot-multi-mongodb:spring boot和mongodb多数据源的使用 spring-boot-package-war:spring-boot打包成war包...
(10) spring-support.jar 这个jar文件包含支持缓存Cache(ehcache)、JCA、JMX、邮件服务(Java Mail、COS Mail)、任务计划Scheduling(Timer、Quartz)方面的类。 (11) spring-web.jar 这个jar文件包含Web应用...
spring-boot-mail:spring boot和邮件服务 spring-boot-mongodb:spring boot和mongodb的使用 spring-boot-multi-mongodb:spring boot和mongodb多数据源的使用 spring-boot-package-war:spring-boot打包成war包...
本案例是通过qq邮箱配置之后通过springboot结合JavaMailSenderIm 发送邮件内容.包含带有纯文本/带有附件文件的
这个jar文件包含支持缓存Cache(ehcache)、JCA、JMX、邮件服务(Java Mail、COS Mail)、任务计划Scheduling(Timer、Quartz)方面的类。 UI方面的用来与模板(Templating)引擎如 Velocity、FreeMarker、...
springcloud-connect:数据连接中心,包含DB、Redis、MQ、Mail等组件的配置入口,只需其他模块在pom中添加依赖并提供相关配置即可快速接入。 springcloud-producer:服务提供者,包含具体的业务逻辑实现等。 spring...
Java消息服务集成,Java Mail集成,远程服务集成。Java管理扩展集成,Java EE连接器架构集成 专注于Spring2.5高级特性的研究。包括忘却的Spring高级话题,Spring最佳实践 对Spring2.5内置的各种XML Schema支持...
Java消息服务集成,Java Mail集成,远程服务集成。Java管理扩展集成,Java EE连接器架构集成 专注于Spring2.5高级特性的研究。包括忘却的Spring高级话题,Spring最佳实践 对Spring2.5内置的各种XML Schema支持...
这个jar文件包含支持缓存Cache(ehcache)、JCA、JMX、邮件服务(Java Mail、COS Mail)、任务计划Scheduling(Timer、Quartz)方面的类。 (11) spring-web.jar 这个jar文件包含Web应用开发时,用到Spring框架...
主要介绍了Spring Boot中利用JavaMailSender发送邮件的方法示例, 相信使用过Spring的众多开发者都知道Spring提供了非常好用的...在Spring Boot的Starter模块中也为此提供了自动化配置。需要的朋友可以参考借鉴。
这个jar文件包含支持缓存Cache(ehcache)、JCA、JMX、邮件服务(Java Mail、COS Mail)、任务计划Scheduling(Timer、Quartz)方面的类。 (11) spring-web.jar 这个jar文件包含Web应用开发时,用到Spring框架时...
用组件做的一个小应用,加了点spring的小功能,依赖注射 方便配置
Thymeleaf 3示例:Spring Mail 这是一个示例应用程序,显示了如何使用Spring和Thymeleaf编写和发送动态电子邮件。 使用Thymeleaf,您可以轻松编写文本和HTML电子邮件。 要了解有关Thymeleaf的更多信息并下载最新...
Spring Boot通过集成spring-boot-starter-mail依赖和相关配置,可以方便地实现邮件发送功能。具体的步骤: 添加依赖:在Spring Boot项目的pom.xml文件中加入spring-boot-starter-mail依赖,如果需要发送模板邮件,还...
NULL 博文链接:https://wisdombrave.iteye.com/blog/546508