2 releases
0.3.1 | Jun 16, 2024 |
---|---|
0.3.0 | Jun 15, 2024 |
0.2.0 |
|
0.1.0 |
|
#102 in Email
15KB
254 lines
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.
Dependencies
~5–33MB
~501K SLoC