18个不稳定版本 (3个破坏性版本)
0.4.5 | 2023年4月28日 |
---|---|
0.4.4 | 2023年3月17日 |
0.3.0 | 2023年2月16日 |
0.2.0 | 2023年1月22日 |
0.1.8 | 2022年11月16日 |
#2 in #send-grid
每月 56 次下载
27KB
446 行
sendgrid_thin
SendGrid V3 API的薄包装器。
它提供了一个简单的API,以阻塞或非阻塞方式使用SendGrid发送电子邮件。
您可以在Actix、Axum或Rocket应用程序中无问题地使用它。
要获取API密钥,您需要在SendGrid上创建账户并创建API密钥。
我推荐使用dotenvy crate从环境变量中加载API密钥。
用法
use sendgrid_thin::{Sendgrid, ContentType};
#[tokio::main]
async fn main() {
let sendgrid = Sendgrid::builder(
"SENDGRID_API_KEY",
"[email protected]",
["[email protected]","[email protected]"],
"subject of email",
"body of email",
)
.set_content_type(ContentType::Html)
.set_send_at(1668281500)
.set_request_timeout(std::time::Duration::from_secs(10))
.set_cc_emails(["[email protected]", "[email protected]"])
.build()
.unwrap();
// Send the email with a non-blocking client
match sendgrid.send().await {
Ok(message) => println!("{message}"),
Err(err) => println!("Error sending email: {err}"),
}
// Send the email with a blocking client (in this case the main function cannot be async)
match sendgrid.send_blocking() {
Ok(message) => println!("{message}"),
Err(err) => println!("Error sending email: {err}"),
}
}
特性
默认特性
blocking
- 启用阻塞客户端
您可以通过向您的Cargo.toml
添加以下内容来禁用默认特性:
sendgrid_thin = { version = "x.x.x", default-features = false }
或当通过cargo add
添加依赖项时
cargo add sendgrid_thin --no-default-features
依赖项
~4–18MB
~246K SLoC