Crates.io | send_email |
lib.rs | send_email |
version | 0.3.1 |
source | src |
created_at | 2024-06-15 13:48:32.107526 |
updated_at | 2024-06-16 10:27:59.336742 |
description | A simple email sender |
homepage | https://github.com/harryhanYuhao/rust_send_email |
repository | https://github.com/harryhanYuhao/rust_send_email |
max_upload_size | |
id | 1272898 |
size | 14,073 |
This library provides a simple api to send email via SMTP. This api is largely a wrapper for lettre
crate.
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.