use-email 0.1.0

Feature-gated facade crate for RustUse email primitives
Documentation
use use_email::{address, auth, envelope, id, mailto, message, smtp};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mailbox = address::Mailbox::new(Some("Jane Doe"), "jane@example.com")?;
    let message_id: id::MessageId = "welcome@example.com".parse()?;
    let message = message::EmailMessage::plain_text("Welcome", "A short note.")
        .with_header("From", mailbox.to_string())?;
    let envelope = envelope::Envelope::new(envelope::EnvelopeSender::new("bounce@example.com")?)
        .with_recipient(envelope::EnvelopeRecipient::new("jane@example.com")?);
    let mailto_uri = mailto::MailtoBuilder::new()
        .to("jane@example.com")?
        .subject("Welcome")
        .build();
    let reply = smtp::SmtpReply::new(smtp::SmtpReplyCode::new(250)?, "OK")?;
    let spf = auth::spf::SpfRecord::new().with_term(auth::spf::SpfTerm::new(
        auth::spf::SpfQualifier::Fail,
        auth::spf::SpfMechanism::All,
    ));

    assert_eq!(message.subject(), Some("Welcome"));
    assert_eq!(message_id.to_string(), "<welcome@example.com>");
    assert_eq!(envelope.recipients().len(), 1);
    assert_eq!(
        mailto_uri.to_string(),
        "mailto:jane@example.com?subject=Welcome"
    );
    assert_eq!(reply.to_string(), "250 OK");
    assert_eq!(spf.to_string(), "v=spf1 -all");

    Ok(())
}