SMTP submission¶
The root mxraven package submits mail to the mxRaven SMTP submission service
on port 587. The service requires STARTTLS and SMTP AUTH.
Composing messages¶
Message is a mutable, chainable builder. A message may be sent more than once.
from mxraven import Message
message = (
Message()
.from_("Acme <noreply@acme.example>")
.reply_to("support@acme.example")
.to("customer@example.com")
.cc("accounting@acme.example")
.bcc("audit@acme.example")
.subject("Invoice 1842")
.header("X-Campaign", "september")
.text("Your invoice is attached.")
.html("<p>Your invoice is attached.</p>")
.attach_file("invoice.pdf", pdf_bytes)
)
- Setting both
textandhtmlproduces amultipart/alternativebody. attach_fileadds a file with anapplication/octet-streamcontent type; useattachto set a content type, orattach_inlineforcid:references.bccadds envelope recipients without a visibleBccheader.null_senderuses a null reverse-path for bounce and auto-generated mail while keeping theFromheader.
Sending raw messages¶
Use send_raw to stream an already serialized RFC 5322 message with an explicit
envelope. The message is not parsed, so the caller is responsible for RFC 5322
correctness.
client.send_raw(
{"from": "bounce@acme.example", "to": ["customer@example.com"]},
raw_message_bytes,
)
Results¶
send returns a Result with the mxRaven message_ref, the final SMTP reply,
and per-recipient acceptance.
Connection pooling¶
A Client keeps a bounded pool of authenticated connections and is safe for
concurrent use. Always call close to release them.