#sendgrid #api-bindings #thin

sendgrid_thin

A small unofficial library to send emails using Sendgrid

18 unstable releases (3 breaking)

0.4.5 Apr 28, 2023
0.4.4 Mar 17, 2023
0.3.0 Feb 16, 2023
0.2.0 Jan 22, 2023
0.1.8 Nov 16, 2022

#67 in Email

Download history 22/week @ 2023-10-27 4/week @ 2023-11-03 4/week @ 2023-11-10 30/week @ 2023-11-17 42/week @ 2023-11-24 58/week @ 2023-12-01 22/week @ 2023-12-08 24/week @ 2023-12-15 39/week @ 2023-12-22 2/week @ 2023-12-29 22/week @ 2024-01-05 4/week @ 2024-01-12 3/week @ 2024-01-19 23/week @ 2024-01-26 27/week @ 2024-02-02 38/week @ 2024-02-09

92 downloads per month

MIT license

27KB
446 lines

sendgrid_thin

Tests

A thin wrapper around the SendGrid V3 API.

It exposes a simple API to send emails with SendGrid with a blocking or non-blocking way.

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};

    #[tokio::main]
    async fn main() {
        let sendgrid = Sendgrid::builder(
                "SENDGRID_API_KEY",
                "from_email@example.com",
                ["to_email_1@example.com","to_email_2@example.com"],
                "subject of email",
                "body of email",
            )
            .set_content_type(ContentType::Html)
            .set_send_at(1668281500)
            .set_request_timeout(std::time::Duration::from_secs(10))
            .set_cc_emails(["cc_email_1@example.com", "cc_email_2@example.com"])
            .build()
            .unwrap();

        // Send the email with a non-blocking client
        match sendgrid.send().await {
            Ok(message) => println!("{message}"),
            Err(err) => println!("Error sending email: {err}"),
        }

        // Send the email with a blocking client (in this case the main function cannot be async)
        match sendgrid.send_blocking() {
            Ok(message) => println!("{message}"),
            Err(err) => println!("Error sending email: {err}"),
        }
    }

Features

Default features

  • blocking - Enables the blocking client

You can disable the default features by adding the following to your Cargo.toml:

sendgrid_thin = { version = "x.x.x", default-features = false }

Or when adding the dependency via cargo add:

cargo add sendgrid_thin --no-default-features

Dependencies

~4–17MB
~254K SLoC