#sendgrid #api-bindings #thin #hyper #tokio

sendgrid_thin

A small unofficial library to send emails using Sendgrid

11 releases

0.2.0 Jan 22, 2023
0.1.9 Dec 5, 2022
0.1.8 Nov 16, 2022

#60 in Email

Download history 36/week @ 2022-11-03 174/week @ 2022-11-10 21/week @ 2022-11-17 10/week @ 2022-11-24 37/week @ 2022-12-01 3/week @ 2022-12-08 1/week @ 2022-12-15 10/week @ 2022-12-22 1/week @ 2022-12-29 1/week @ 2023-01-05 14/week @ 2023-01-12 28/week @ 2023-01-19 14/week @ 2023-01-26

57 downloads per month

MIT license

19KB
263 lines

sendgrid_thin

Tests

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(["to_email_1@example.com", "to_email_2@example.com"])
            .set_from_email("from_email@example.com")
            .set_subject("subject of email")
            .set_body("body of email");

        // Optional
        sendgrid
            .set_content_type(ContentType::Html)
            .set_send_at(1_668_281_500)
            .set_cc_emails(["cc_email_1@example.com", "cc_email_2@example.com"]);

        // Send the email
        match sendgrid.send() {
            Ok(message) => println!("{}", message),
            Err(err) => println!("Error sending email: {}", err),
        }
    }

Dependencies

~2.6–4MB
~103K SLoC