Crates.io | mail-send |
lib.rs | mail-send |
version | 0.4.9 |
source | src |
created_at | 2022-05-30 14:37:41.65649 |
updated_at | 2024-07-03 13:06:22.701854 |
description | E-mail delivery library with SMTP and DKIM support |
homepage | https://github.com/stalwartlabs/mail-send |
repository | https://github.com/stalwartlabs/mail-send |
max_upload_size | |
id | 597025 |
size | 149,921 |
mail-send is a Rust library to build, sign and send e-mail messages via SMTP. It includes the following features:
Send a message via an SMTP server that requires authentication:
// Build a simple multipart message
let message = MessageBuilder::new()
.from(("John Doe", "john@example.com"))
.to(vec![
("Jane Doe", "jane@example.com"),
("James Smith", "james@test.com"),
])
.subject("Hi!")
.html_body("<h1>Hello, world!</h1>")
.text_body("Hello world!");
// Connect to the SMTP submissions port, upgrade to TLS and
// authenticate using the provided credentials.
SmtpClientBuilder::new("smtp.gmail.com", 587)
.implicit_tls(false)
.credentials(("john", "p4ssw0rd"))
.connect()
.await
.unwrap()
.send(message)
.await
.unwrap();
Sign a message with DKIM and send it via an SMTP relay server:
// Build a simple text message with a single attachment
let message = MessageBuilder::new()
.from(("John Doe", "john@example.com"))
.to("jane@example.com")
.subject("Howdy!")
.text_body("These pretzels are making me thirsty.")
.attachment("image/png", "pretzels.png", [1, 2, 3, 4].as_ref());
// Sign an e-mail message using RSA-SHA256
let pk_rsa = RsaKey::<Sha256>::from_rsa_pem(TEST_KEY).unwrap();
let signer = DkimSigner::from_key(pk_rsa)
.domain("example.com")
.selector("default")
.headers(["From", "To", "Subject"])
.expiration(60 * 60 * 7); // Number of seconds before this signature expires (optional)
// Connect to an SMTP relay server over TLS.
// Signs each message with the configured DKIM signer.
SmtpClientBuilder::new("smtp.gmail.com", 465)
.connect()
.await
.unwrap()
.send_signed(message, &signer)
.await
.unwrap();
More examples of how to build messages are available in the mail-builder
crate.
Please note that this library does not support parsing e-mail messages as this functionality is provided separately by the mail-parser
crate.
To run the testsuite:
$ cargo test --all-features
or, to run the testsuite with MIRI:
$ cargo +nightly miri test --all-features
Licensed under either of
at your option.
Copyright (C) 2020-2022, Stalwart Labs Ltd.