email-notif

Crates.ioemail-notif
lib.rsemail-notif
version1.0.1
sourcesrc
created_at2023-01-03 16:16:23.664721
updated_at2023-01-03 16:20:52.581684
descriptionEmail notification for status of long running processes.
homepagehttps://github.com/cbosoft/email-notif-rs
repositoryhttps://github.com/cbosoft/email-notif-rs
max_upload_size
id750241
size9,429
Chris B (cbosoft)

documentation

README

email-notif-rs

Email notification of process status. For long-running processes (e.g. training a ML model or running a simulation) it can be useful to be sent a notification on completion. Email is a handy way to recieve this.

This is a rust implementation of my python script email_notifier.

Installation

This package is on cargo. Add the dependency to your projects as:

[dependency]
email-notif-rs = "1.0.0"

Usage

You need to tell the library where emails should be sent from. I don't want to put email config in programs, so it's in a config file in your home dir. The sending email should be one you don't mind having a password in plain text in a json file. (i.e. one that was set up for the purposes of sending notifications.)

{
  "smtp_server": "smtp.example.com",
  "sender_email": "notifications@bar.com",
  "password": "notVerySecureAtAll",
  "recipient_email": "foo@bar.com",
  "port": 587
}

With the config set, you can now use the library from a program as follows:

use email_notif::EmailNotifier;
use crate::foo::long_running_process;

fn main() {
  EmailNotifier::new("Simulation Run")
    .capture(
      |em| {
        for i in 0..10 {
          long_running_process();
          em.send_update(format!("iteration {i} complete"));
        }
      }
    );
}

The above will send an update notification every time an iteration is complete, and an email when the process completes successfully. In addition, an email will be sent if the process results in panic. (Only an unwind panic, however.)

Commit count: 15

cargo fmt