spring使用Email邮件系统
1.提供邮件信息发送接收,附件绑定功能.
1.配置spring-email.xml文件
<context:property-placeholder location="classpath:email.properties" ignore-unresolvable="true"/>
<bean id="webEmailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${demo-web.host}"/>
<property name="port" value="${demo-web.port}"/>
<property name="username" value="${bus-web.username}"/>
<property name="password" value="${demo-web.password}"/>
<property name="javaMailProperties">
<props>
<!--设置是否需要身份验证-->
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
<bean id="smg" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value="${demo-web.from}"/>
<property name="to" value="${demo-web.to}"/>
</bean>
<bean id="emailBean" class="com.demo.service.email.WebEmail"/>
定义Email消息类
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component; /**
* *********************************************************
* <p/>
* Author: XiJun.Gong
* Date: 2016-08-19 15:04
* Version: default 1.0.0
* Class description:
* <p/>
* *********************************************************
*/
@Component(value = "emailBean")
public class WebEmail { private static Logger logger = LoggerFactory.getLogger(WebEmail.class); @Resource(name = "webEmailSender")
private JavaMailSenderImpl mailSender;
@Resource(name = "smg")
private SimpleMailMessage MailMessage; public void send(String subject, String content) { try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);
messageHelper.setFrom(MailMessage.getFrom());
messageHelper.setSubject(subject); //主题
messageHelper.setText(content); //内容
messageHelper.setTo(MailMessage.getTo()); //发送给
/*
ClassPathResource file = new ClassPathResource("new file(path)");
messageHelper.addAttachment(file.getFilename(), file); //添加附件
*/
mailSender.send(mimeMessage); //发送邮件 } catch (Exception e) {
logger.error("the email send error ! {}", e);
}
} }
3. email.properties配置文件
bus-web.subject=123
bus-web.content=123
bus-web.from=vipgxjun@163.com
bus-web.to=8888888@qq.com
bus-web.host=smtp.163.com
bus-web.port=25
bus-web.username=xijun.gong
bus-web.password=*******
4.运行即可

spring使用Email邮件系统的更多相关文章
- 利用Velocity结合Spring发email
在spring中发mail是一件容易的事,如果利用Velocity做mail的模板来发送就更得心应手了. 首先,还是简单描述sping中的配置,发mail需要一个mail的engin: <bea ...
- 第19章-使用Spring发送Email
1 配置Spring发送邮件 Spring Email抽象的核心是MailSender接口.顾名思义,MailSender的实现能够通过连接Email服务器实现邮件发送的功能,如图19.1所示. 图1 ...
- Spring 发送 Email
本文转自:http://zl198751.iteye.com/blog/757617 看到了本文,收获颇丰,感谢之至! 首先介绍下Email的发送流程: 需要选中smtp邮件服务器,Yahoo不提供免 ...
- Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference
Spring comes with a useful ‘org.springframework.mail.javamail.JavaMailSenderImpl‘ class to simplify ...
- 使用Spring发送Email
配置Spring发送邮件 Spring发送邮件底层还是使用JavaMail,我在http://www.cnblogs.com/lz2017/p/6882925.html 中记录过关于JavaMail的 ...
- 使用Spring 发送 Email !!!!
邮件服务器: 邮件服务器提供了邮件系统的基本结构,包括邮件传输,邮件分发,邮件存储等功能,以确保邮件能够发送到互联网中的任意地方. 邮件服务器就像我们生活中的邮局,为人们提供邮件服务.要保证邮件被正确 ...
- 使用spring 并加载模板发送Email 发邮件 java 模板
以下例子是使用spring发送email,然后加载到固定的模板,挺好的,大家可以试试 需要使用到spring-context 包 和 com.springsource.org.apache.veloc ...
- Spring 4 使用Freemarker模板发送邮件&添加附件
前言 Spring对Java的邮件发送提供了很好的支持,提供了超级简单的API,大大简化了Java邮件发送功能的开发. Spring对Email的支持是基于JavaMail API开发的,所以,我们在 ...
- Spring 4 官方文档学习 Spring与Java EE技术的集成
本部分覆盖了以下内容: Chapter 28, Remoting and web services using Spring -- 使用Spring进行远程和web服务 Chapter 29, Ent ...
随机推荐
- Saltstack之multi-master
一.实验环境: 1.salt版本: [root@master master]# salt --versions-report Salt: 2015.5.10 Python: 2.7.5 (defaul ...
- <Interview Problem>最小的“不重复数”
百度的一道笔试题目,看到博客园讨论挺热烈的,也写一下玩玩. 实现思想:举个简单的例子11233,从高位到低位开始判断是否有重复数,高位有重复数后,首先修改高位的,高位修改后变为12233,因为要求最小 ...
- linux的mount(挂载)命令详解
本文介绍mount命令的用法,以及技巧光盘镜像文件.移动硬盘及U盘的方法. 挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用 ...
- vs2010取消显示所有文件 崩溃
这属于vs2010的bug,以下是微软官方对些问题的回应: i am still investigating the problem, but looks like the issue is caus ...
- sql获取时间
SELECT CONVERT(varchar(10), getdate(), 120)--当前年月日,Example:2013-11-19 SELECT CONVERT(varchar(10), ge ...
- PHP Problem with the SSL CA cert (path? access rights?)
1.php使用curl模块报错问题 开发遇到问题,直接使用系统的curl命令正常,使用php的curl模块报错 错误:PHP Problem with the SSL CA cert (path? a ...
- Windows光标形状
::SetCursor( LoadCursor(NULL, IDC_XXX) ); IDC_ARROW (plain) IDC_HELP (arrow + question mark) IDC_APP ...
- 模板——RMQ
就是模板 #include <cstdio> #include <cstring> #include <iostream> using namespace std; ...
- android HAL 教程(含实例)
http://www.cnblogs.com/armlinux/archive/2012/01/14/2396768.html Android Hal 分析 ...
- 简单介绍一下R中的几种统计分布及常用模型
统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...