ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-06-15 09:54:37  阅读:264  来源: 互联网

标签:status smtp pub 发送 str Vigil config email 邮件


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

标签:status,smtp,pub,发送,str,Vigil,config,email,邮件
来源: https://www.cnblogs.com/rongfengliang/p/11026526.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有