SpringCloud微服务实战——搭建企业级开发框架(四十三):多租户可配置的电子邮件发送系统设计与实现

Java52

在日常生活中,电子邮件已经被聊天软件、短信等更便捷的信息传递方式所取代。然而,在我们的日常工作中,我们的重要信息通知非常需要存档和追溯,所以邮件是信息传递不可或缺的渠道。对于我们在工作中经常使用的系统,邮件发送功能基本集成在其中。

[En]

In daily life, email has been replaced by chat software, text messages and other more convenient ways of information transmission. However, in our daily work, our important information notices are very necessary to be archived and traced, so mail is an indispensable channel for information transmission. For the systems that we often use in our work, mail sending functions are basically integrated in them.

SpringBoot提供了基于JavaMail的starter,我们只要按照官方的说明配置邮件服务器信息,即可使我们的系统拥有发送电子邮件的功能。但是,在我们GitEgg开发框架的实际业务开发过程中,有两个问题需要解决:一个是SpringBoot邮箱服务器的配置是配置在配置文件中的,不支持灵活的界面配置。另外一个是我们的开发框架需要支持多租户,那么此时需要对SpringBoot提供的邮件发送功能进行扩展,以满足我们的需求。

那么,基于以上需求和问题,我们对GitEgg框架进行扩展,增加以下功能:

1、扩展系统配置:将邮箱服务器的配置信息持久化到数据库、Redis缓存,和配置文件一起使用,制定读取优先级。
2、扩展多租户配置:如果系统开启了多租户功能,那么在邮件发送时,首先读取租户的当前配置,如果没有配置,那么在读取系统配置。
3、自有选择服务器:用户可在系统界面上选择指定的邮箱服务器进行邮件发送。
4、提供邮件发送模板:用户可选择预先制定的邮件模板进行发送特定邮件。
5、增加发送数量、频率限制:增加配置,限制模板邮件的发送数量和频率。
6、保存邮件发送记录:不一定把所有附件都保存,只需保存邮件发送关键信息,如果需要保存所有附件等需要自己扩展。

同一个租户可以配置多个电子邮件服务器,但只能启用一个服务器。默认情况下,系统通知类功能仅使用已启用的服务器传递邮件。当需要自定义时,例如指定直接从页面发送邮件的服务器,则提供可选界面并指定发送邮件的服务器。

[En]

The same tenant can configure multiple e-mail servers, but only one server can be enabled. By default, the system notification class feature uses only enabled servers for mail delivery. When there is a need for customization, such as specifying a server to send mail directly from the page, provide an optional interface and specify a server to send mail.

一、集成spring-boot-starter-mail扩展基础邮件发送功能

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长