diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 9b62bf233..33469e3c2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailSendVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; @@ -81,4 +82,11 @@ public class MailAccountController { list.sort(Comparator.comparing(MailAccountDO::getId)); return success(MailAccountConvert.INSTANCE.convertList02(list)); } + @PostMapping("/send") + @ApiOperation("发送邮件") + @PreAuthorize("@ss.hasPermission('system:mail-account:send')") + public CommonResult sendMail(MailSendVO mailSendVO){ + mailAccountService.sendMail(mailSendVO); + return success(true); + } } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java new file mode 100644 index 000000000..41d9d03b4 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/vo/send/MailSendVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.system.controller.admin.mail.vo.send; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; +@Data +public class MailSendVO { + + @ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com") + private String from; + + @ApiModelProperty(value = "标题" , example = "标题") + private String title; + + @ApiModelProperty(value = "内容" , example = "内容") + private String content; + + @ApiModelProperty(value = "收件人" , required = true , example = "yudaoyuanma@123.com") + private List tos; + + @ApiModelProperty(value = "附件" , example = "附件编码") + private List fileIds; + + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 195bc0bb0..2147af7fe 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -16,7 +16,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="MailAccount对象", description="") +@ApiModel(value="MailAccount对象", description="邮箱账号") @TableName(value = "system_mail_account", autoResultMap = true) public class MailAccountDO extends BaseDO implements Serializable { @@ -37,7 +37,7 @@ public class MailAccountDO extends BaseDO implements Serializable { private String host; @TableField("port") - private String port; + private Integer port; @TableField("sslEnable") private Boolean sslEnable; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 759263a40..3cc0acb02 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailSendVO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import java.util.List; @@ -30,4 +31,6 @@ public interface MailAccountService { PageResult getMailAccountPage(MailAccountPageReqVO pageReqVO); List getMailAccountList(); + + void sendMail(MailSendVO mailSendVO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 11625a7bc..98aa646c7 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -1,12 +1,17 @@ package cn.iocoder.yudao.module.system.service.mail.impl; +import cn.hutool.extra.mail.MailAccount; +import cn.hutool.extra.mail.MailUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailSendVO; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; +import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; +import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; @@ -35,6 +40,9 @@ public class MailAccountServiceImpl implements MailAccountService { @Resource private MailAccountMapper mailAccountMapper; + @Resource + private MailTemplateMapper mailTemplateMapper; + @Override public Long create(MailAccountCreateReqVO createReqVO) { // username 要校验唯一 @@ -81,6 +89,35 @@ public class MailAccountServiceImpl implements MailAccountService { return mailAccountMapper.selectList(); } + @Override + public void sendMail(MailSendVO mailSendVO) { + // FIXME 查询模版信息 查询模版多条时 使用规则是什么 + List mailTemplateDOList = mailTemplateMapper.selectList( + "username",mailSendVO.getFrom() + ); + //查询账号信息 + MailAccountDO mailAccountDO = mailAccountMapper.selectOne( + "from",mailSendVO.getFrom() + ); + // FIXME 模版和邮件内容合成方式未知 + String content = mailSendVO.getContent(); + String templateContent = ""; + // 后续功能 TODO :附件查询 + //List fileIds = mailSendVO.getFileIds(); + + //装载账号信息 + MailAccount account = new MailAccount(); + account.setHost(mailAccountDO.getHost()); + account.setPort(mailAccountDO.getPort()); + account.setAuth(true); + account.setFrom(mailAccountDO.getFrom()); + account.setUser(mailAccountDO.getUsername()); + account.setPass(mailAccountDO.getPassword()); + account.setSslEnable(mailAccountDO.getSslEnable()); + //发送 + MailUtil.send(account , mailSendVO.getTos() , mailSendVO.getTitle() , mailSendVO.getContent() , false); + } + private void validateMailAccountExists(Long id) { if (mailAccountMapper.selectById(id) == null) { throw exception(MAIL_ACCOUNT_NOT_EXISTS);