[][src]Struct sendgrid::SGClient

pub struct SGClient { /* fields omitted */ }

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

impl SGClient[src]

pub fn new<S: Into<String>>(key: S) -> SGClient[src]

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.

pub fn send(&self, mail_info: Mail<'_>) -> SendgridResult<Response>[src]

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

This example is not tested
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

impl Clone for SGClient[src]

impl Debug for SGClient[src]

Auto Trait Implementations

impl !RefUnwindSafe for SGClient

impl Send for SGClient

impl Sync for SGClient

impl Unpin for SGClient

impl !UnwindSafe for SGClient

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.