Vigil 发送多人邮件通知的处理

Vigil 默认是只能发送单人邮件,但是我们有需要发送多个的场景。
解决方法:

  • 大家使用一样的账户登陆
  • 使用邮件组
  • 修改下源码
    为了学习下Vigil 的构建,以及原理,我简单通过修改源码的方式(目前支持4个人,但是代码是写死的)
    后边可以进一步优化

项目github 代码

代码我已经提交github 了
https://github.com/rongfengliang/myvigil-multiemail

修改部分说明

Vigil 使用toml 进行配置管理,我们需要做的是添加新的邮件发送字段(struct 结构体中)

src/config/config.rs 文件

  • 代码如下
 
#[derive(Deserialize)]
pub struct ConfigNotifyEmail {
    pub to: String,
    pub from: String,
    pub to2: String,
    pub to3: String,
    pub to4: String,
    pub to5: String,
    #[serde(default = "defaults::notify_email_smtp_host")]
    pub smtp_host: String,
    #[serde(default = "defaults::notify_email_smtp_port")]
    pub smtp_port: u16,
    pub smtp_username: Option<String>,
    pub smtp_password: Option<String>,
    #[serde(default = "defaults::notify_email_smtp_encrypt")]
    pub smtp_encrypt: bool,
    #[serde(default = "defaults::notify_email_reminders_only")]
    pub reminders_only: bool,
}
  • email 发送部分

    email 使用了lettre 包,但是新旧版本有点不一样,需要注意使用的是0.8,此处代码写死了4个人

            let email_message = EmailBuilder::new()
                .to(email_config.to.as_str())
                .to(email_config.to2.as_str())
                .to(email_config.to3.as_str())
                .to(email_config.to4.as_str())
                .from((
                    email_config.from.as_str(),
                    APP_CONF.branding.page_title.as_str(),
                ))
                .subject(format!(
                    "{} | {}",
                    notification.status.as_str().to_uppercase(),
                    &nodes_label
                ))
                .text(message)
                .build()
                .or(Err(true))?;
 

关于构建

Vigil 需要使用nightly 版本,但应该是1.36起对于lettre 有破坏行影响,同时官方也修改了代码
兼容问题很多,解决方法, 安装指定日志版本的nightly 版本,我构建使用docker 多阶段处理
参考dockerfile

FROM rustlang/rust:nightly AS build
USER root
WORKDIR /app
COPY . /app
# 处理构建工具版本的核心部分
RUN rustup install nightly-2019-01-17
RUN rustup default nightly-2019-01-17-x86_64-unknown-linux-gnu
RUN cargo -V
RUN cargo build --release
FROM debian:stretch-slim
WORKDIR /usr/src/vigil
COPY ./res/assets/ ./res/assets/
COPY --from=build /app/target/release/vigil /usr/local/bin/vigil
COPY ./res/assets/ ./res/assets/
RUN apt-get update
RUN apt-get install -y libstrophe-dev libssl-dev
CMD [ "vigil", "-c", "/etc/vigil.cfg" ]
EXPOSE 8080
 

配置文件说明

现在我们可以配置4个可以发送的邮箱了,参考格式

[notify.email]
from = "status@crisp.chat"
to = "status@crisp.chat"
to2 = "status@crisp.chat"
to3 = "status@crisp.chat"
to4 = "status@crisp.chat"
to5 = "status@crisp.chat"
smtp_host = "localhost"
smtp_port = 587
smtp_username = "user-access"
smtp_password = "user-password"
smtp_encrypt = false

说明

修改的代码部分很简单,也很low,主要是关于构建工具的问题,版本依赖太严重,实际上碰到问题还是
多看看官方文档,深入了解下工具,这样可以加速我们解决问题,比如上边的关于构建工具版本的,主要
就是下载指定版本的

 
rustup install nightly-2019-01-17
rustup default nightly-2019-01-17-x86_64-unknown-linux-gnu

参考资料

https://github.com/rongfengliang/myvigil-multiemail
https://www.rust-lang.org/tools/install
https://forge.rust-lang.org/other-installation-methods.html

posted on   荣锋亮  阅读(458)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-06-15 nginx-vod-module && docker && docker-compose 测试
2018-06-15 使用nginx-vod-module hls &&dash &&Thumbnail 处理
2016-06-15 webpack 多entry 配置
2015-06-15 Sublime Text3注册码 (备用)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示