- 浏览: 994358 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1441)
- 软件思想&演讲 (9)
- 行业常识 (250)
- 时时疑问 (5)
- java/guava/python/php/ruby/R/scala/groovy (213)
- struct/spring/springmvc (37)
- mybatis/hibernate/JPA (10)
- mysql/oracle/sqlserver/db2/mongdb/redis/neo4j/GreenPlum/Teradata/hsqldb/Derby/sakila (268)
- js/jquery/jqueryUi/jqueryEaseyUI/extjs/angulrJs/react/es6/grunt/zepto/raphael (81)
- ZMQ/RabbitMQ/ActiveMQ/JMS/kafka (17)
- lucene/solr/nuth/elasticsearch/MG4J (167)
- html/css/ionic/nodejs/bootstrap (19)
- Linux/shell/centos (56)
- cvs/svn/git/sourceTree/gradle/ant/maven/mantis/docker/Kubernetes (26)
- sonatype nexus (1)
- tomcat/jetty/netty/jboss (9)
- 工具 (17)
- ETL/SPASS/MATLAB/RapidMiner/weka/kettle/DataX/Kylin (11)
- hadoop/spark/Hbase/Hive/pig/Zookeeper/HAWQ/cloudera/Impala/Oozie (190)
- ios/swift/android (9)
- 机器学习&算法&大数据 (18)
- Mesos是Apache下的开源分布式资源管理框架 (1)
- echarts/d3/highCharts/tableau (1)
- 行业技能图谱 (1)
- 大数据可视化 (2)
- tornado/ansible/twisted (2)
- Nagios/Cacti/Zabbix (0)
- eclipse/intellijIDEA/webstorm (5)
- cvs/svn/git/sourceTree/gradle/jira/bitbucket (4)
- jsp/jsf/flex/ZKoss (0)
- 测试技术 (2)
- splunk/flunm (2)
- 高并发/大数据量 (1)
- freemarker/vector/thymeleaf (1)
- docker/Kubernetes (2)
- dubbo/ESB/dubboX/wso2 (2)
最新评论
1、发送邮件配置文件springmail_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<a href="http://www.springframework.org/schema/beans" style="font-size: 14px;">http://www.springframework.org/schema/beans</a>"
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" style="font-size: 14px;">http://www.w3.org/2001/XMLSchema-instance</a>"
xsi:schemaLocation="<a href="http://www.springframework.org/schema/beans" style="font-size: 14px;">http://www.springframework.org/schema/beans</a>
<a href="http://www.springframework.org/schema/beans/spring-beans.xsd" style="font-size: 14px;">http://www.springframework.org/schema/beans/spring-beans.xsd</a>"
>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.qq.com" />
<property name="port" value="25" />
<property name="username" value="xxxx@qq.com" />
<property name="password" value="xxxxxxx" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<!-- 根据情况可进行设置
<prop key="mail.smtp.timeout">2500</prop>
-->
</props>
</property>
</bean>
</beans>
Java代码 收藏代码
2、发送邮件java类
package com.yihongyu.exec.javamail;
import java.io.File;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
/**
* SpringMail测试类
*
* @author tzz
*
*/
public class SpringMailUtil {
private ApplicationContext context = null;
public SpringMailUtil() {
context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/springmail_config.xml");
}
// 简单邮件
public void simpleSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
SimpleMailMessage mail = new SimpleMailMessage();
mail.setFrom("xxx@qq.com");
mail.setTo("xxx@qq.com");
mail.setSubject(" 测试spring Mail");
mail.setText("你好,java");
mailSender.send(mail);
}
// 带附件
public void attachmentSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxx@qq.com");
helper.setTo("xxx@qq.com");
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
// 多附件
public void moreAttachmentSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxxx@qq.com");
helper.setTo("xxx@qq.com");
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\zqt.sql"));
helper.addAttachment("zqt.sql", attachment);
FileSystemResource attachment2 = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment2);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
// 抄送
public void copySend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxxxx@qq.com");
helper.setTo("xxxx@qq.com");
helper.setCc("xxxx@qq.com");
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\zqt.sql"));
helper.addAttachment("zqt.sql", attachment);
FileSystemResource attachment2 = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment2);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
// 多附件、多人发送/抄送
public void moreUserSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxxxx@qq.com");
helper.setTo("xxxxx@qq.com");// 发送
// helper.setCc("xxxxxx@qq.com");//抄送
// helper.setTo(new InternetAddress[] { new InternetAddress("xxxxx@qq.com"),
// new InternetAddress("xxxx@qq.com") });
helper.setCc(new InternetAddress[] { new InternetAddress("xxxxxx@qq.com"),
new InternetAddress("xxxxxx@qq.com") });
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\zqt.sql"));
helper.addAttachment("zqt.sql", attachment);
FileSystemResource attachment2 = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment2);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SpringMailUtil springMailUtil = new SpringMailUtil();
// 简单邮件
// springMailUtil.simpleSend();
// 附件
// springMailUtil.attachmentSend();
// 多附件
// springMailUtil.moreAttachmentSend();
// 抄送
// springMailUtil.copySend();
// 多附件、多人发送/抄送
springMailUtil.moreUserSend();
System.out.println("发送成功");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<a href="http://www.springframework.org/schema/beans" style="font-size: 14px;">http://www.springframework.org/schema/beans</a>"
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" style="font-size: 14px;">http://www.w3.org/2001/XMLSchema-instance</a>"
xsi:schemaLocation="<a href="http://www.springframework.org/schema/beans" style="font-size: 14px;">http://www.springframework.org/schema/beans</a>
<a href="http://www.springframework.org/schema/beans/spring-beans.xsd" style="font-size: 14px;">http://www.springframework.org/schema/beans/spring-beans.xsd</a>"
>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.qq.com" />
<property name="port" value="25" />
<property name="username" value="xxxx@qq.com" />
<property name="password" value="xxxxxxx" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<!-- 根据情况可进行设置
<prop key="mail.smtp.timeout">2500</prop>
-->
</props>
</property>
</bean>
</beans>
Java代码 收藏代码
2、发送邮件java类
package com.yihongyu.exec.javamail;
import java.io.File;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
/**
* SpringMail测试类
*
* @author tzz
*
*/
public class SpringMailUtil {
private ApplicationContext context = null;
public SpringMailUtil() {
context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/springmail_config.xml");
}
// 简单邮件
public void simpleSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
SimpleMailMessage mail = new SimpleMailMessage();
mail.setFrom("xxx@qq.com");
mail.setTo("xxx@qq.com");
mail.setSubject(" 测试spring Mail");
mail.setText("你好,java");
mailSender.send(mail);
}
// 带附件
public void attachmentSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxx@qq.com");
helper.setTo("xxx@qq.com");
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
// 多附件
public void moreAttachmentSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxxx@qq.com");
helper.setTo("xxx@qq.com");
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\zqt.sql"));
helper.addAttachment("zqt.sql", attachment);
FileSystemResource attachment2 = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment2);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
// 抄送
public void copySend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxxxx@qq.com");
helper.setTo("xxxx@qq.com");
helper.setCc("xxxx@qq.com");
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\zqt.sql"));
helper.addAttachment("zqt.sql", attachment);
FileSystemResource attachment2 = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment2);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
// 多附件、多人发送/抄送
public void moreUserSend() {
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MimeMessage mime = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mime, true, "utf-8");
helper.setFrom("xxxxx@qq.com");
helper.setTo("xxxxx@qq.com");// 发送
// helper.setCc("xxxxxx@qq.com");//抄送
// helper.setTo(new InternetAddress[] { new InternetAddress("xxxxx@qq.com"),
// new InternetAddress("xxxx@qq.com") });
helper.setCc(new InternetAddress[] { new InternetAddress("xxxxxx@qq.com"),
new InternetAddress("xxxxxx@qq.com") });
helper.setSubject("测试spring Mail附件");
// 需要将附件显示在html中
helper.setText("你好,java", true);
FileSystemResource attachment = new FileSystemResource(new File("E:\\zqt.sql"));
helper.addAttachment("zqt.sql", attachment);
FileSystemResource attachment2 = new FileSystemResource(new File("E:\\Test2.doc"));
helper.addAttachment(MimeUtility.encodeWord("测试.doc"), attachment2);// 解决附件中文编码问题
mailSender.send(mime);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SpringMailUtil springMailUtil = new SpringMailUtil();
// 简单邮件
// springMailUtil.simpleSend();
// 附件
// springMailUtil.attachmentSend();
// 多附件
// springMailUtil.moreAttachmentSend();
// 抄送
// springMailUtil.copySend();
// 多附件、多人发送/抄送
springMailUtil.moreUserSend();
System.out.println("发送成功");
}
}
发表评论
-
Spring Boot
2017-09-26 09:51 252Spring Boot是由Pivotal团 ... -
spring AOP中切点
2017-08-25 09:59 861在spring AOP中,需要使用AspectJ的切点表达式 ... -
Spring JdbcTemplate详解
2017-07-19 16:12 558JdbcTemplate简介 Spring对数据库的操 ... -
Spring相关
2017-04-20 16:10 430我是一个Java开发者,之前知道Spring属于这个公司,就 ... -
spring.schemas、spring.handlers的使用
2017-02-28 13:55 1678报错信息:Configuration problem: Un ... -
Spring的一个命名空间的名称空间处理程序没有找到
2017-02-25 15:20 9051. 问题 本文将讨论Spring中最常见的配置问题 —— ... -
到底EJB是什么
2016-12-06 10:05 420到底EJB是什么?被口口相传的神神秘秘的,百度一番,总觉得 ... -
Spring MVC 和 Servlet 一样,都不是线程安全的
2016-04-28 01:06 628你的理解是对的,Spring MVC 和 Servlet 一 ... -
springmvc的control 的线程是否安全的问题
2016-05-31 10:09 324关于java Servlet,Struts,springM ... -
框架的一些学习
2016-02-03 14:53 222java aopalliance-1.0.jar这个包是AOP ... -
Metrics介绍和Spring的集成
2016-02-02 16:56 904Metrics可以为你的代码的运行提供无与伦 ... -
spring mvc常用的注解
2016-01-22 14:28 664spring mvc常用的注解: ... -
Spring的常用注解
2016-01-20 16:07 612Spring2.5引入注解式处理器 @Controlle ... -
通过Spring的配置,添加多个数据源,制作多个qlMapClient,iBatis或Hibernate的各个DAO
2016-12-27 10:25 478通过Spring的配置,添加多个数据源,制作多个qlMapCl ... -
springmvc避免IE执行AJAX时,返回JSON出现下载文件
2017-01-01 23:35 823<!-- 避免IE执行AJAX时,返回JSON出现下载文 ... -
springMVC的@ResponseBody出现乱码解决方法
2017-01-02 00:23 347使用@ResponseBody出现乱码解决方法 1、 Re ... -
Spring中的Bean的注入方式
2017-01-02 00:27 502一 setter方法注入 配置文件如下: <bean ... -
@Resource和@Autowire的区别
2017-01-02 00:27 663@Resource和@Autowire的区别 在java代码中 ... -
Spring中继承并简化了Quartz
2017-01-02 00:27 635Quartz是一个强大的企业级任务调度框架,Spring中继承 ... -
spring方法拦截器 MethodInterceptor
2017-01-03 09:38 1657使用到spring方法拦截器 MethodIntercepto ...
相关推荐
邮件发送者 from 一般采用固定的形式写到配置文件中。 (2)富文本邮件 在日常使用的过程中,通常在邮件中加入图片或者附件来丰富邮件的内容 发送 HTML 格式邮件 邮件发送支持以 HTML 的形式去构建我们喜欢的...
包含了spring的ioc,aop,任务调度,cxf、jws示例以及邮件发送跟任务调度。里面包含了需要用到的jar包以及xml配置文件。还有示例代码。很方便学习
2.2修改yml配置文件 2.3编写测试发送邮件 2.4 测试结果 2.4.1 发送基本内容 2.4.2 发送复杂内容 我们使用java程序发送邮件,属于使用第三方客户端发送邮件 使用第三方客户端发送邮件也需要先通过认证(登录): 官方...
添加依赖:在Spring Boot项目的pom.xml文件中加入spring-boot-starter-mail依赖,如果需要发送模板邮件,还可以加入Thymeleaf相关的依赖。 配置邮件:在application.properties或者application.yml中配置邮件发送的...
Spring Boot邮件发送(powernode CD2207)(教学视频+源代码) SpringBoot提供了发送邮件的功能 SpringBoot实现邮件功能是非常的方便...3.2 application.yml配置文件 3.3 发送普通内容的邮件 3.4 发送复杂内容的邮件
Spring邮件发送系统:基于Java构建,包含67个文件,包括60个XML配置文件、3个Java类文件、2个.gitignore文件、1个Idea项目文件(.iml)和1个YAML配置文件。该项目是一个Spring email的最简单入门案例,用于演示如何...
编程语言+JAVAspring+邮件...它介绍了JAVAspring的邮件服务的概念、原理和作用,以及如何使用JAVAspring的邮件服务来发送邮件,包括邮件的配置、构建、发送、接收、附件、模板等内容,以及一些配置文件和注解的用法。
本文档主要是讲述使用spring自带的邮件发送功能,以配置文件的方式来完成
该文档写了spring结合quartz定时发送邮件,有详细的配置文件,和相关代码,稍加研究就可以运行。
我自己从pro spring书上修改过来的发邮件程序,在配置文件javaMailSender.xml中把自己邮箱的地址,用户名,密码,发送邮件的服务器修改一下就能使用了。 此邮件程序还有定时功能,到你定的时刻后它就开始发邮件,...
使用邮件请在gateway模块配置文件中配置自己的邮箱信息 跟着课件学习的,启动服务可能需要关联启动:nacos sentinel seata skywalking其中某些中间件 配合博客...
本案例是通过qq邮箱配置之后通过springboot结合JavaMailSenderIm 发送邮件内容.包含带有纯文本/带有附件文件的
配置文件 创建和管理bean。 4.spring-context-4.1.1.RELEASE.jar 在基础IOC功能上提供扩展服务,此外还提供许多企业级服务的支持,有邮件服务、任务调度、JNDI定位,EJB集成、远程访问、缓存以及多种视图层框架的...
参照Maven3 in Action编写的由Maven3搭建的发送邮件的工程,只要简单的修改配置文件和测试类中的邮件用户信息即可运行。
config|[Spring Cloud Alibaba(二)配置中心多项目、多配置文件、分目录实现](https://github.com/smltq/spring-boot-demo/blob/master/cloud-alibaba/README2.md) Sentinel|[Spring Cloud Alibaba(三)Sentinel...
邮件管理:发送邮件、搜索邮件 文件管理:上传文件、文件列表、文件删除 公告管理:公告未读提醒、发布公告、查询公告、公告阅读人列表 excel下载:自定义sql导出excel、也可在页面展示sql结果数据 字典管理:...
- chapter2-1-1:[配置文件详解:自定义属性、随机数、多环境配置等](http://blog.didispace.com/springbootproperties/) ### Web开发 - chapter3-1-1:[构建一个较为复杂的RESTful API以及单元测试]...
13.8. Spring对分段文件上传(multipart file upload)的支持 13.8.1. 介绍 13.8.2. 使用MultipartResolver 13.8.3. 在表单中处理分段文件上传 13.9. 使用Spring的表单标签库 13.9.1. 配置标签库 13.9.2. form...
13.8. Spring对分段文件上传(multipart file upload)的支持 13.8.1. 介绍 13.8.2. 使用MultipartResolver 13.8.3. 在表单中处理分段文件上传 13.9. 使用Spring的表单标签库 13.9.1. 配置标签库 13.9.2. form标签 ...