1、自定义发送邮件功能实现(html代码后端有xss过滤器,需要配置)
This commit is contained in:
parent
768dc8bc1a
commit
f14d5004a5
|
|
@ -22,6 +22,6 @@ public interface RemoteMailFeign {
|
|||
@GetMapping("mail/send-weather-mail")
|
||||
void sendWeatherMailForRPC();
|
||||
|
||||
@PostMapping("mail/sendMail")
|
||||
R sendMail(@RequestBody MailBean mailBean);
|
||||
@PostMapping("mail/sendMailForRPC")
|
||||
R sendMailForRPC(@RequestBody MailBean mailBean);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class RemoteMailFactory implements FallbackFactory<RemoteMailFeign> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public R sendMail(MailBean mailBean) {
|
||||
public R sendMailForRPC(MailBean mailBean) {
|
||||
log.error("远程发送邮件调用异常:"+cause.getMessage());
|
||||
return R.fail("远程发送邮件调用异常:"+cause.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ import org.aspectj.lang.JoinPoint;
|
|||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 登录切面类
|
||||
*
|
||||
|
|
@ -22,7 +23,7 @@ import org.springframework.stereotype.Component;
|
|||
@Aspect
|
||||
public class LoginAspect {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private RemoteMailFeign remoteMailFeign;
|
||||
|
||||
/**
|
||||
|
|
@ -50,7 +51,7 @@ public class LoginAspect {
|
|||
"<img src=\"" + loginUser.getSysUser().getAvatar() + "\" alt=\"头像\">" +
|
||||
" <p>当前IP地址:" + loginUser.getSysUser().getLoginIp() + "</p>");
|
||||
|
||||
remoteMailFeign.sendMail(mailBean);
|
||||
remoteMailFeign.sendMailForRPC(mailBean);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
//发送邮件
|
||||
export function sendMail(data) {
|
||||
return request({
|
||||
url: '/warning/mail/send-mail',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
|
||||
<el-row :gutter="15">
|
||||
<el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="邮件标题" prop="subject" style="width:800px">
|
||||
<el-input v-model="formData.subject" placeholder="请输入标题" :maxlength="100" clearable
|
||||
prefix-icon='el-icon-eleme' :style="{width: '100%'}"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<el-form-item label="收件人" prop="recipient">
|
||||
<el-input v-model="formData.recipient" placeholder="请输入收件人邮箱" :maxlength="100" clearable
|
||||
prefix-icon='el-icon-eleme' :style="{width: '100%'}"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="" prop="recipientSuffix" label-width="0px">
|
||||
<el-select
|
||||
v-model="formData.recipientSuffix"
|
||||
placeholder="邮箱"
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 150px">
|
||||
<el-option
|
||||
v-for="dict in dict.type.email_service"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<!--md内容 -->
|
||||
<el-col :span="24">
|
||||
<el-form-item label="邮件内容" prop="content">
|
||||
<editor v-model="formData.content" :min-height="450"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="24">
|
||||
<el-form-item size="mini">
|
||||
<el-button type="primary"
|
||||
v-hasPermi="['sendmail-send']"
|
||||
@click="sendForm">发送
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-form>
|
||||
</el-row>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {sendMail} from "@/api/business/tools/sendmail";
|
||||
|
||||
export default {
|
||||
name: "SendMail",
|
||||
|
||||
dicts: ['email_service'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
formData: {
|
||||
subject: "",
|
||||
recipient: undefined,
|
||||
recipientSuffix: undefined,
|
||||
content: undefined,
|
||||
|
||||
|
||||
},
|
||||
|
||||
rules: {
|
||||
subject: [
|
||||
{required: true, message: '请输入标题', trigger: 'blur'},
|
||||
{min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur'}
|
||||
],
|
||||
content: [
|
||||
{required: true, message: '请输入内容', trigger: 'blur'},
|
||||
{min: 1, max: 50000, message: '长度在 1 到 50000 个字符', trigger: 'blur'}
|
||||
],
|
||||
recipient: [
|
||||
{required: true, message: '请输入收件人', trigger: 'blur'},
|
||||
{min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'}
|
||||
|
||||
],
|
||||
recipientSuffix: [
|
||||
{required: true, message: '请选择后缀', trigger: 'blur'},
|
||||
{min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'}
|
||||
]
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'dict.type.email_service'(newVal) {
|
||||
if (newVal[0]) {
|
||||
this.formData.recipientSuffix = newVal[0].value
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
sendForm() {
|
||||
this.$refs['elForm'].validate(valid => {
|
||||
if (!valid) return
|
||||
|
||||
let data = {
|
||||
subject: this.formData.subject,
|
||||
recipient: this.formData.recipient + this.formData.recipientSuffix,
|
||||
content: this.formData.content
|
||||
}
|
||||
this.$modal.loading("请稍后...")
|
||||
sendMail(data).then(res => {
|
||||
this.$modal.notifySuccess("发送成功")
|
||||
this.$modal.closeLoading()
|
||||
this.formData.subject=""
|
||||
this.formData.recipient=""
|
||||
this.formData.recipientSuffix=""
|
||||
}).catch(err =>{
|
||||
this.$modal.closeLoading()
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
|
@ -107,6 +107,7 @@ import AddOrUpdate from "./memberlevel-add-or-update";
|
|||
import {delMemberLevel, getMemberLevelList} from "@/api/mall/member/level";
|
||||
|
||||
export default {
|
||||
name:"Member-Level",
|
||||
data() {
|
||||
return {
|
||||
dataForm: {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
package com.xjs.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.xjs.domain.mall.MailBean;
|
||||
import com.xjs.domain.mall.MailVo;
|
||||
import com.xjs.service.MailService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 邮件服务控制器
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-04-13
|
||||
*/
|
||||
|
|
@ -22,6 +28,17 @@ public class MailController {
|
|||
private MailService mailService;
|
||||
|
||||
|
||||
@PostMapping("send-mail")
|
||||
@ApiOperation("发送邮件")
|
||||
@Log(title = "发送邮件", businessType = BusinessType.INSERT)
|
||||
public AjaxResult sendMail(@RequestBody MailVo mailVo) {
|
||||
MailBean mailBean = new MailBean();
|
||||
BeanUtils.copyProperties(mailVo, mailBean);
|
||||
mailBean.setMailType(MailBean.MailType.HTML);
|
||||
mailService.sendMail(mailBean);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
//-----------------------------------远程调用------------------------------------
|
||||
@GetMapping("/send-weather-mail")
|
||||
@ApiOperation("发送天气邮件ForRPC")
|
||||
|
|
@ -30,11 +47,12 @@ public class MailController {
|
|||
}
|
||||
|
||||
|
||||
@PostMapping("/sendMail")
|
||||
@PostMapping("/sendMailForRPC")
|
||||
@ApiOperation("发送邮件ForRPC")
|
||||
public R<?> sendMail(@RequestBody MailBean mailBean) {
|
||||
public R<?> sendMailForRPC(@RequestBody MailBean mailBean) {
|
||||
mailService.sendMail(mailBean);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package com.xjs.domain.mall;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 邮件数据传输对象
|
||||
* @author xiejs
|
||||
* @since 2022-04-14
|
||||
*/
|
||||
|
||||
public class MailVo implements Serializable {
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/**
|
||||
* 邮件接收人
|
||||
*/
|
||||
private String recipient;
|
||||
/**
|
||||
* 邮件主题
|
||||
*/
|
||||
private String subject;
|
||||
/**
|
||||
* 邮件内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MailVo{" +
|
||||
"recipient='" + recipient + '\'' +
|
||||
", subject='" + subject + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
public void setRecipient(String recipient) {
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ public class MailServer {
|
|||
@MailLog
|
||||
public Boolean sendMail(MailBean mailBean) {
|
||||
|
||||
if (redisService.hasKey(MAIL_SENDER)) {
|
||||
if (redisService.hasKey(MAIL_STATUS)) {
|
||||
throw new RuntimeException("邮件发送频繁!请稍后重试!");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue