使用RuoYi-Vue-Plus接入QQ邮件服务

maven依赖

<!--邮箱验证-->
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

yml文件配置

spring: 
  mail: #邮箱
    default-encoding: UTF-8
    host: smtp.qq.com
    username: 你的QQ邮箱@qq.com            #发送邮件的邮箱
    password: xxxxxxxxxxx  #发送邮件邮箱的KEY,可以去百度一下邮箱如何开启stmp 就知道了
    port: 465
    auth: true
    properties:
      mail.smtp.socketFactory.fallback: false
      mail.smtp.socketFactory.port: 465
      mail.smtp.socketFactory.class: javax.net.ssl.SSLSocketFactory

邮件发送实体

package com.ruoyi.email.entity;

/**
 * 邮件发送实体类
 *
 * @author: wangghua
 * @version: 1.0
 * @date: 2022-03-16 16:14
 **/
import lombok.Data;

@Data
public class EmailEntity {
   
    private String sendTo;  //收件邮箱
    private String title;   //邮箱标题
    private String detail;  //邮箱内容
    private String fileList;  //附件内容(上传到阿里云oss的附件,多附件用英文逗号隔开,文件名不能包含逗号)
}

请求响应对象AjaxResult类

package com.ruoyi.common.core.domain;

import cn.hutool.http.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 操作消息提醒
 *
 * @author Lion Li
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel("请求响应对象")
public class AjaxResult<T> {
   

	private static final long serialVersionUID = 1L;

	/**
	 * 状态码
	 */
	@ApiModelProperty("消息状态码")
	private int code;

	/**
	 * 返回内容
	 */
	@ApiModelProperty("消息内容")
	private String msg;

	/**
	 * 数据对象
	 */
	@ApiModelProperty("数据对象")
	private T data;

	/**
	 * 初始化一个新创建的 AjaxResult 对象
	 *
	 * @param code 状态码
	 * @param msg  返回内容
	 */
	public AjaxResult(int code, String msg) {
   
		this.code = code;
		this.msg = msg;
	}

	/**
	 * 返回成功消息
	 *
	 * @return 成功消息
	 */
	public static AjaxResult<Void> success() {
   
		return AjaxResult.success("操作成功");
	}

	/**
	 * 返回成功数据
	 *
	 * @return 成功消息
	 */
	public static <T> AjaxResult<T> success(T data) {
   
		return AjaxResult.success("操作成功", data);
	}

	/**
	 * 返回成功消息
	 *
	 * @param msg 返回内容
	 * @return 成功消息
	 */
	public static AjaxResult<Void> success(String msg) {
   
		return AjaxResult.success(msg, null);
	}

	/**
	 * 返回成功消息
	 *
	 * @param msg  返回内容
	 * @param data 数据对象
	 * @return 成功消息
	 */
	public static <T> AjaxResult<T> success(String msg, T data) {
   
		return new AjaxResult<>(HttpStatus.HTTP_OK, msg, data);
	}

	/**
	 * 返回错误消息
	 *
	 * @return
	 */
	public static AjaxResult<Void> error() {
   
		return AjaxResult.error("操作失败");
	}

	/**
	 * 返回错误消息
	 *
	 * @param msg 返回内容
	 * @return 警告消息
	 */
	public static AjaxResult<Void> error(String msg) {
   
		return AjaxResult.error(msg, null);
	}

	/**
	 * 返回错误消息
	 *
	 * @param msg  返回内容
	 * @param data 数据对象
	 * @return 警告消息
	 */
	public static <T> AjaxResult<T> error(String msg, T data) {
   
		return new AjaxResult<>(HttpStatus.HTTP_INTERNAL_ERROR, msg, data);
	}

	/**
	 * 返回错误消息
	 *
	 * @param code 状态码
	 * @param msg  返回内容
	 * @return 警告消息
	 */
	public static AjaxResult<Void> error(int code, String msg) {
   
		return new AjaxResult<>(code, msg, null);
	}

}

邮件发送业务类EmailService

package com.ruoyi.email.service;

import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.email.entity.EmailEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值