pub struct SGClient { /* private fields */ }
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§
Source§impl SGClient
impl SGClient
Sourcepub fn new<S: Into<String>>(key: S) -> SGClient
pub fn new<S: Into<String>>(key: S) -> SGClient
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.
Sourcepub fn set_host<S: Into<String>>(&mut self, host: S)
pub fn set_host<S: Into<String>>(&mut self, host: S)
Sets the host to use for the API. This is useful if you are using a proxy or a local development server. It should be a full URL, including the protocol.
Sourcepub async fn send(&self, mail_info: Mail<'_>) -> SendgridResult<Response>
pub async fn send(&self, mail_info: Mail<'_>) -> SendgridResult<Response>
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;
#[tokio::main]
async 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)
.await?;
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SGClient
impl !RefUnwindSafe for SGClient
impl Send for SGClient
impl Sync for SGClient
impl Unpin for SGClient
impl !UnwindSafe for SGClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more