A MoonBit email library with facade APIs for composing, encoding, and sending messages over SMTP.
// assuming you import the `moonbit-community/email` facade package
///|
let from = Mailbox::new("sender@example.com", Some("Sender")) |> must_ok
///|
let to = Mailbox::address_only("reader@example.com") |> must_ok
///|
let message = compose_plain_text(from, [to], "Greetings", "Hello from MoonBit!")
|> must_ok
///|
let envelope = envelope_for(message) |> must_ok
///|
let encoded = to_rfc5322(message)///|
let config = SmtpConfig::new(
"smtp.example.com",
465,
security=SmtpSecurity::Tls,
auth=SmtpAuth::Plain("sender@example.com", "app-password"),
)
///|
let outcome = send_plain_text(
config,
from,
[to],
"Greetings",
"Hello from MoonBit!",
)
|> must_ok///|
let attachment = Body::attachment_file(
"report.pdf",
"/path/to/report.pdf",
content_type=infer_content_type("report.pdf"),
)
|> must_ok
///|
let message = compose_mixed(from, [to], "Monthly report", [
Body::plain_text("See attachment."),
attachment,
])
|> must_ok///|
let transport = FakeTransport::new()
///|
let outcome = transport.send_message(envelope, message) |> must_okmoon run cmd/main -- \
--sender your-account@example.com \
--recipient someone@example.com \
--auth-code your-auth-code \
--subject "MoonBit email test" \
--body "Hello from moonbit-community/email"moon check
moon test
moon info
moon fmtasync fn send_html(config : SmtpConfig, from : Mailbox, to : Array[Mailbox], subject : String, content : String, cc? : Array[Mailbox], bcc? : Array[Mailbox], headers? : Array[Header], mail_from? : Mailbox) -> Result[DeliveryOutcome, ValidationError]async fn send_plain_text(config : SmtpConfig, from : Mailbox, to : Array[Mailbox], subject : String, content : String, cc? : Array[Mailbox], bcc? : Array[Mailbox], headers? : Array[Header], mail_from? : Mailbox) -> Result[DeliveryOutcome, ValidationError]Install
Download zipA MoonBit email library with facade APIs for composing, encoding, and sending messages over SMTP.