sendgrid_thin
A thin wrapper around the SendGrid V3 API.
It does not use the crate tokio
or hyper
and is therefore very lightweight and do not interfere with your existing runtime.
You can use it inside your Actix, Axum or Rocket application without any problems.
To get the API key, you need to create an account on SendGrid and create an API key.
I recommend the dotenvy crate to load the API key from an environment variable.
Usage
use sendgrid_thin::{Sendgrid, ContentType};
fn main() {
let mut sendgrid = Sendgrid::new("SENDGRID_API_KEY");
// Required
sendgrid
.set_to_emails(&["[email protected]", "[email protected]"])
.set_from_email("[email protected]")
.set_subject("subject of email")
.set_body("body of email");
// Optional
sendgrid
.set_content_type(ContentType::Html)
.set_send_at(1668281500)
.set_cc_emails(&["[email protected]", "[email protected]"]);
// Send the email
match sendgrid.send() {
Ok(message) => println!("{}", message),
Err(err) => println!("Error sending email: {}", err),
}
}