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

bin+lib resend_email_rs

Resend.com 的轻量级邮件 SDK

1 个不稳定版本

0.1.0 2024年4月26日

#108 in 电子邮件

MIT 许可证

18KB
88

Resend 邮件库

Resend 邮件库为 Rust 应用程序中的电子邮件操作提供全面解决方案。此 crate 支持各种电子邮件功能,包括纯文本和 HTML 电子邮件,并简化了附件处理。

即将推出

我很快就会添加批量电子邮件方法 :)

入门指南

要使用 Resend 邮件库,将其添加到您的 Cargo.toml

[dependencies]
resend_rs = "0.1.0"

功能

示例

以下是使用此库发送不同类型电子邮件的示例

客户端认证

use resend_rs::ResendClient;

let client = ResendClient::new("your_auth_token".to_string());

请确保将 your_auth_token 替换为您实际的 Resend API 令牌。

发送纯文本电子邮件

use resend_rs::{ResendClient, MailText};

let client = ResendClient::new("your_auth_token".to_string());

let mail = MailText {
    from: "[email protected]",
    to: vec!["[email protected]"],
    subject: "Test Email",
    text: "Hello, this is a test email.",
    attachments: None,
};
let email_sent_status: Email = client.send(&mail).await.unwrap();

发送 HTML 电子邮件

use resend_rs::{ResendClient, MailHtml};

let client = ResendClient::new("your_auth_token".to_string());
let mail = MailHtml {
    from: "[email protected]",
    to: vec!["[email protected]"],
    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: "[email protected]",
    to: vec!["[email protected]"],
    subject: "Test Email with Attachment",
    text: "Please find the attachment.",
    attachments: Some(vec![attachment]),
};
let email_sent_status: Email = client.send(&mail).await.unwrap();

处理成功和错误

库为操作提供详细的反馈

每个电子邮件发送操作都返回一个 Result<Email, Error>,指示结果,这使得程序化处理成功或诊断问题变得容易。

依赖关系

~4–15MB
~204K SLoC