Crates.io | resend_email_rs |
lib.rs | resend_email_rs |
version | 0.1.0 |
source | src |
created_at | 2024-04-26 00:04:44.412403 |
updated_at | 2024-04-26 00:04:44.412403 |
description | Lightweight mailing SDK for Resend.com |
homepage | |
repository | https://github.com/floris-xlx/resend_email_rs |
max_upload_size | |
id | 1220824 |
size | 50,593 |
The Resend Email Library provides comprehensive solutions for email operations within Rust applications. This crate supports various email functionalities, including plain text and HTML emails, and facilitates handling attachments.
I will add the bulk emailing method soon :)
To use the Resend Email Library, add it to your Cargo.toml
:
[dependencies]
resend_rs = "0.1.0"
Here are examples of how to send different types of emails using this library:
use resend_rs::ResendClient;
let client = ResendClient::new("your_auth_token".to_string());
Make sure to replace your_auth_token
with your actual Resend API token.
use resend_rs::{ResendClient, MailText};
let client = ResendClient::new("your_auth_token".to_string());
let mail = MailText {
from: "floris@xylex.ai",
to: vec!["recipient@example.com"],
subject: "Test Email",
text: "Hello, this is a test email.",
attachments: None,
};
let email_sent_status: Email = client.send(&mail).await.unwrap();
use resend_rs::{ResendClient, MailHtml};
let client = ResendClient::new("your_auth_token".to_string());
let mail = MailHtml {
from: "floris@xylex.ai",
to: vec!["recipient@example.com"],
subject: "Hello World",
html: "<h1>Welcome</h1><p>This is an HTML email.</p>",
attachments: None,
};
let email_sent_status: Email = client.send(&mail).await.unwrap();
use resend_rs::{ResendClient, MailText, Attachment};
let client = ResendClient::new("your_auth_token".to_string());
let attachment = Attachment {
content: vec![0, 1, 2, 3],
filename: "example.txt",
};
let mail = MailText {
from: "floris@xylex.ai",
to: vec!["recipient@example.com"],
subject: "Test Email with Attachment",
text: "Please find the attachment.",
attachments: Some(vec![attachment]),
};
let email_sent_status: Email = client.send(&mail).await.unwrap();
The library provides detailed feedback for operations:
Success::EmailSent
: Indicates that the email was successfully sent.
Error::ReqwestError
: If there is a network-related error.
Error::ResendError
: If the API returns a non-success status.
Every email send operation returns a Result<Email, Error>
indicating the outcome, which makes it easy to handle success or diagnose issues programmatically.