Expand description
§resend-rs
A minimal Resend client.
Add with:
cargo add resend-rs
cargo add tokio -F macros,rt-multi-thread
Emails are sent via the Resend
client which provides both a synchronous and
asynchronous send method. The two are mutually exclusive and accessible via the
blocking
feature. The crate uses reqwest and serde
internally.
§Documentation
Crate documentation is available in docsrs. Example usage is available in the get started guide on the Resend website, you can also find examples in the API reference.
§Features
blocking
to enable the blocking client.native-tls
to use system-native TLS. Enabled by default.rustls-tls
to use TLS backed byrustls
.
§Variables
RESEND_API_KEY
to enableimpl Default
for aResend
client (Required).RESEND_BASE_URL
to override the default base address:https://api.resend.com
(Optional).RESEND_RATE_LIMIT
to set the maximum amount of requests you can send per second. By default, this is 9 (Resend defaults to 10). See the docs for more information.
WARNING: Rate limiting only works when using the async version (default) of the crate
§Rate Limits
Resend implements rate limitting on their API which can sometimes get in the way of whatever you are trying to do. This crate handles that in 2 ways:
-
Firstly all requests made by the
Resend
client are automatically rate limitted to 9 req/1.1s to avoid collisions with the 10 req/s limit that Resend imposes at the time of writing this.Note that the client can be safely cloned as well as used in async/parallel contexts and the rate limit will work as intended. The only exception to this is creating 2 clients via the
Resend::new
orResend::with_client
methods which should be avoided, use.clone()
instead. -
Secondly, a couple of helper methods as well as macros are implemented in the
rate_limit
module that allow catching rate limit errors and retrying the request instead of failing.These were implemented to handle cases where this crate is used in a horizontally scaled environment and thus needs to work on different machines at the same time in which case the internal rate limits alone cannot guarantee that there will be no rate limit errors.
As long as only one program is interacting with the Resend servers on your behalf, this module does not need to be used.
§Examples
use resend_rs::types::{CreateEmailBaseOptions, Tag};
use resend_rs::{Resend, Result};
#[tokio::main]
async fn main() -> Result<()> {
let resend = Resend::default();
let from = "Acme <onboarding@a.dev>";
let to = ["delivered@resend.dev"];
let subject = "Hello World!";
let email = CreateEmailBaseOptions::new(from, to, subject)
.with_text("Hello World!")
.with_tag(Tag::new("hello", "world"));
let id = resend.emails.send(email).await?.id;
println!("id: {id}");
Ok(())
}
Modules§
- Parsing for Resend’s Events.
- Helper methods for retrying requests in case of a rate limit error.
Resend
API services.- Request and response types.
Macros§
- Equivalent to
send_with_retry
. - Equivalent to
send_with_retry_opts
.
Structs§
- The Resend client.
Enums§
- Error type for operations of a
Resend
client.