#send-email #resend #plain-text #html #com #attachment #bulk

bin+lib resend_email_rs

Lightweight mailing SDK for Resend.com

1 unstable release

0.1.0 Apr 26, 2024

#157 in Email

MIT license

18KB
88 lines

Resend Email Library

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.

Coming soon

I will add the bulk emailing method soon :)

Getting Started

To use the Resend Email Library, add it to your Cargo.toml:

[dependencies]
resend_rs = "0.1.0"

Features

Examples

Here are examples of how to send different types of emails using this library:

Authenticating the client

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.

Sending a Plain Text Email

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();

Sending an HTML Email

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();

Sending an Email with Attachments

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();

Handling Success and Errors

The library provides detailed feedback for operations:

Every email send operation returns a Result<Email, Error> indicating the outcome, which makes it easy to handle success or diagnose issues programmatically.

Dependencies

~4–15MB
~191K SLoC