spring框架发送邮件(单发,群发,发送多个附件)

前言:发送邮件是常用技术,主流框架springboot整合的邮件发送非常简单好用(想了解的从这里可以传送),传统的javamail这里也不做介绍(想了解的从这里传送,现在都用框架开发所以也不怎么用的上),我现在做的项目是基于jeecg框架,所以这里以spring框架整合javamail邮箱服务器为qq为例。


1.项目是基于maven构建的spring项目(基本的依赖这里就不说了),引入mail的依赖

<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.4</version>
		</dependency>

2.在项目的resources中新建mail.properties文件,加入如下配置(这里的参数不了解可以点击第二个传送门,或者自行百度一下)

mail.host=smtp.qq.com  //qq邮箱服务器
mail.username=发送人邮箱
mail.password=生成的授权码
mail.smtp.auth=true   //认证
mail.smtp.timeout=25000  //超时
mail.smtp.port=25 //端口

3.在项目的resources中新建mail.xml文件,加入如下配置内容(最下面那个mailutil是我建的工具类,根据情况替换成你们建的类的路径跟名称)

<?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:p="http://www.springframework.org/schema/p"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop.xsd
                        http://www.springframework.org/sch
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值