use resend_rs::types::CreateEmailBaseOptions;use resend_rs::{Resend, Result};#[tokio::main]async fn main() -> Result<()> { let resend = Resend::new("re_xxxxxxxxx"); let from = "Acme <onboarding@resend.dev>"; let to = ["delivered@resend.dev"]; let subject = "Hello World"; let email = CreateEmailBaseOptions::new(from, to, subject) .with_html("<strong>It works!</strong>"); let _email = resend.emails.send(email).await?; Ok(())}
Instead of using Resend::new and hardcoding the API key, the RESEND_API_KEY environment variable
can be used instead. The Resend::default() should be used in that scenario instead.
Another popular option is to use a .env file for environment variables. You can use the
dotenvy crate for that:
cargo add dotenvy
// main.rsuse dotenvy::dotenv;use resend_rs::types::CreateEmailBaseOptions;use resend_rs::{Resend, Result};#[tokio::main]async fn main() -> Result<()> { let _env = dotenv().unwrap(); let resend = Resend::default(); let from = "Acme <onboarding@resend.dev>"; let to = ["delivered@resend.dev"]; let subject = "Hello World"; let email = CreateEmailBaseOptions::new(from, to, subject) .with_html("<strong>It works!</strong>"); let _email = resend.emails.send(email).await?; Ok(())}