Struct sendgrid::SGClient[][src]

pub struct SGClient { /* fields omitted */ }
Expand description

This is the struct that allows you to authenticate to the SendGrid API. It contains the API key which allows you to send messages as well as a blocking request client.

Implementations

Makes a new SendGrid cient with the specified API key. This will panic if you are using the default TLS backend and do not have a default TLS backend available. If you are using the RustTLS backend, this can never panic because RustTLS is statically linked.

Sends a messages through the SendGrid API. It takes a Mail struct as an argument. It returns the string response from the API as JSON.

Example

use sendgrid::SendgridError;

fn main() -> Result<(), SendgridError> {
    let my_secret_key = std::env::var("SENDGRID_KEY").expect("need SENDGRID_KEY to test");
    use sendgrid::{Mail, SGClient};

    let mail = Mail::new()
        .add_from("my-email@address.com")
        .add_text("hi!")
        .add_subject("Hello")
        .add_to(("your-email@address.com", "Your Name").into());
    let response = SGClient::new(my_secret_key)
        .send(mail)?;
    Ok(())
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.