lumenmail/message
Email message builder module. Provides a fluent API for constructing RFC 5322 compliant email messages.
Types
An email attachment.
pub type Attachment {
Attachment(
filename: String,
content_type: ContentType,
data: BitArray,
inline: Bool,
content_id: option.Option(String),
)
}
Constructors
-
Attachment( filename: String, content_type: ContentType, data: BitArray, inline: Bool, content_id: option.Option(String), )
Content type for email body parts.
pub type ContentType {
TextPlain
TextHtml
MultipartAlternative
MultipartMixed
MultipartRelated
ApplicationOctetStream
Custom(mime_type: String)
}
Constructors
-
TextPlain -
TextHtml -
MultipartAlternative -
MultipartMixed -
MultipartRelated -
ApplicationOctetStream -
Custom(mime_type: String)
Content transfer encoding.
pub type Encoding {
SevenBit
EightBit
QuotedPrintable
Base64
}
Constructors
-
SevenBit -
EightBit -
QuotedPrintable -
Base64
An email header.
pub type Header {
Header(name: String, value: String)
}
Constructors
-
Header(name: String, value: String)
Email message structure.
pub type Message {
Message(
from: option.Option(types.Address),
reply_to: option.Option(types.Address),
to: List(types.Address),
cc: List(types.Address),
bcc: List(types.Address),
subject: option.Option(String),
text_body: option.Option(String),
html_body: option.Option(String),
attachments: List(Attachment),
headers: List(Header),
priority: Priority,
message_id: option.Option(String),
in_reply_to: option.Option(String),
references: List(String),
)
}
Constructors
-
Message( from: option.Option(types.Address), reply_to: option.Option(types.Address), to: List(types.Address), cc: List(types.Address), bcc: List(types.Address), subject: option.Option(String), text_body: option.Option(String), html_body: option.Option(String), attachments: List(Attachment), headers: List(Header), priority: Priority, message_id: option.Option(String), in_reply_to: option.Option(String), references: List(String), )
Values
pub fn add_reference(message: Message, id: String) -> Message
Adds a reference message ID (for threading).
pub fn all_recipients(message: Message) -> List(types.Address)
Gets all recipients (to + cc + bcc).
pub fn attachment(
message: Message,
filename: String,
content_type: ContentType,
data: BitArray,
) -> Message
Adds an attachment.
pub fn bcc(message: Message, address: types.Address) -> Message
Adds a recipient to the BCC field.
pub fn bcc_email(message: Message, email: String) -> Message
Adds a recipient to BCC using just an email string.
pub fn bcc_many(
message: Message,
addresses: List(types.Address),
) -> Message
Sets multiple BCC recipients at once.
pub fn body(
message: Message,
text: String,
html: String,
) -> Message
Sets both text and HTML body (multipart/alternative).
pub fn build(message: Message) -> Result(String, String)
Builds the raw email message as a string.
pub fn cc(message: Message, address: types.Address) -> Message
Adds a recipient to the CC field.
pub fn cc_email(message: Message, email: String) -> Message
Adds a recipient to CC using just an email string.
pub fn cc_many(
message: Message,
addresses: List(types.Address),
) -> Message
Sets multiple CC recipients at once.
pub fn content_type_to_string(ct: ContentType) -> String
Converts content type to MIME string.
pub fn format_address(address: types.Address) -> String
Formats an address for use in email headers.
pub fn format_address_list(
addresses: List(types.Address),
) -> String
Formats a list of addresses for use in email headers.
pub fn from_email(message: Message, email: String) -> Message
Sets the sender using just an email string.
pub fn from_name_email(
message: Message,
name: String,
email: String,
) -> Message
Sets the sender with name and email.
pub fn generate_boundary() -> String
Generates a random boundary string for multipart messages.
pub fn in_reply_to(message: Message, id: String) -> Message
Sets the In-Reply-To header (for threading).
pub fn inline_attachment(
message: Message,
filename: String,
content_type: ContentType,
data: BitArray,
content_id: String,
) -> Message
Adds an inline attachment (e.g., for images in HTML).
pub fn reply_to(
message: Message,
address: types.Address,
) -> Message
Sets the reply-to address.
pub fn to(message: Message, address: types.Address) -> Message
Adds a recipient to the To field.
pub fn to_email(message: Message, email: String) -> Message
Adds a recipient to To using just an email string.
pub fn to_many(
message: Message,
addresses: List(types.Address),
) -> Message
Sets multiple To recipients at once.