send_email

Crates.iosend_email
lib.rssend_email
version0.3.1
sourcesrc
created_at2024-06-15 13:48:32.107526
updated_at2024-06-16 10:27:59.336742
descriptionA simple email sender
homepagehttps://github.com/harryhanYuhao/rust_send_email
repositoryhttps://github.com/harryhanYuhao/rust_send_email
max_upload_size
id1272898
size14,073
Harry Han (harryhanYuhao)

documentation

README

Simple Send Email Client in Rust

This library provides a simple api to send email via SMTP. This api is largely a wrapper for lettre crate.

Quick Start

To send a email, provide two structs Sender, Email, and a vector of recipient to send_email function:

use send_email::*;

fn main() {
    let sender = Sender::new(
        "example@gmail.com", // credential_username
        "PASSWORD",    // password
        "Eric Elon",         // sender name. Leave empty if not needed
        SmtpServer::Gmail,   // provider
        "example@gmail.com", // reply_addr
    );

    let message = EmailContent::new(
        "Hi",                           // subject
        "Hello, this is a test email.", // body
        false,                          // is_html
        vec!["pic.jpg", "Cargo.toml"],  // path to attachments
    );

    let recipients = vec![
        Recipient::new(
            "Esther Frank",      // name
            "example@gmail.com", // email
            Category::To,        // category. can be To, Cc, or Bcc
        ),
        Recipient::new(
            "", // name leave empty if not needed
            "example@outlook.com",
            Category::Cc, // Category.
        ),
    ];

    send_email(&sender, &message, &recipients).unwrap();
}

Password can be stored in toml file and the program can read from it securely:

// main.rs
let sender = Sender::new_passwd_from_file(
    "example.com",           // credential_username
    ".password.toml",        // file_path to password
    "Francis Waverley",      // sender_name
    SmtpServer::Gmail,       // provider
);
# .password.toml
password = "PASSWORD"

Sending an email is easy as this.

Commit count: 18

cargo fmt