mail-send

crates.io build docs.rs crates.io

mail-send is a Rust library to build, sign and send e-mail messages via SMTP or third party services such as Mailchimp, Mailgun, etc. It includes the following features:

Usage Example

Send a message via an SMTP server that requires authentication:

```rust // 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!") .htmlbody("

Hello, world!

") .textbody("Hello world!");

// Connect to an SMTP relay server over TLS and
// authenticate using the provided credentials.
SmtpClient::new("smtp.gmail.com")
    .credentials("john", "p4ssw0rd")
    .connect_tls()
    .await
    .unwrap()
    .send(message)
    .await
    .unwrap();

```

Sign a message with DKIM and send it via an SMTP relay server:

```rust // 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!") .textbody("These pretzels are making me thirsty.") .binaryattachment("image/png", "pretzels.png", [1, 2, 3, 4].as_ref());

// Set up DKIM signer
let dkim = DKIM::from_pkcs1_pem_file("./cert.pem")
    .unwrap()
    .domain("example.com")
    .selector("2022")
    .headers(["From", "To", "Subject"]) // Headers to sign
    .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.
SmtpClient::new("smtp.example.com")
    .dkim(dkim)
    .connect_tls()
    .await
    .unwrap()
    .send(message)
    .await
    .unwrap();

```

Send a message via Mailchimp:

```rust // 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!") .htmlbody("

Hello, world!

") .textbody("Hello world!");

// Send the message via Mailchimp
MailchimpClient::new("YOUR_API_KEY")
    .send(message)
    .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.

Testing

To run the testsuite:

bash $ cargo test --all-features

or, to run the testsuite with MIRI:

bash $ cargo +nightly miri test --all-features

License

Licensed under either of

at your option.

Copyright

Copyright (C) 2020-2022, Stalwart Labs Ltd.

See [COPYING] for the license.