HTML rendering for swift-email.
Status: pre-cutover integration package. This package is the home for swift-email's client-facing rendering surface. The live surface today is the Apple Mail
.emlformat; the HTML rendering pipeline itself is staged underParked/and does not compile until its dependencies exist in the institute HTML stack (seeParked/Email/README.md).
import Email_HTML provides:
AppleMail.Message— wraps anEmailas an RFC 5322 message carrying the Apple-specific headers Apple Mail applications expect.descriptionrenders the complete.emlcontent. Conversion failures throw a typed error; a fresh RFC 4122 identifier is generated when none is supplied.
The Email compose model and the RFC 5322 vocabulary are re-exported, so the import is self-contained.
dependencies: [
.package(url: "https://github.com/swift-foundations/swift-email-html.git", branch: "main")
].target(
name: "YourTarget",
dependencies: [
.product(name: "Email HTML", package: "swift-email-html")
]
)import Email_HTML
let email = try Email(
to: [EmailAddress("recipient@example.com")],
from: EmailAddress("sender@example.com"),
subject: "Hello",
body: "Hello, World!"
)
let message = try AppleMail.Message(from: email)
let emlContent = message.descriptionAppleMail.Message(from:) throws a typed AppleMail.Message.Error:
AppleMail.Message.Error
├─ conversion(Email.ConversionError) // the email failed to convert into an RFC 5322 message
└─ identifier(Random.Error) // the message identifier failed to generate
Because the initializer declares throws(AppleMail.Message.Error), the catch
can be exhaustive over the enum:
import Email_HTML
do {
let message = try AppleMail.Message(from: email)
let emlContent = message.description
} catch .conversion(let conversionError) {
// The email failed to convert into an RFC 5322 message.
print("Conversion failed: \(conversionError)")
} catch .identifier(let randomError) {
// The universally-unique message identifier failed to generate.
print("Identifier generation failed: \(randomError)")
}Licensed under the Apache License, Version 2.0.