I’ve launched SwiftMail right now, a light-weight open-source Swift framework designed to simplify sending and receiving emails by way of IMAP and SMTP.
For AgentCorp, my Swift-based LLM agent framework, I wanted a technique to allow my AI brokers to learn and write emails. These brokers would work together with customers by way of e mail—studying new messages by way of IMAP and sending responses by way of SMTP. After exploring the Swift package deal panorama, I discovered solely MailCore2 (final up to date in 2020) and NIO IMAP as viable contenders. MailCore2 had construct points, and NIO IMAP, though promising, required vital extra work earlier than it could possibly be virtually used.
SwiftMail bridges this hole by leveraging Apple’s Swift NIO framework and enhancing each IMAP and SMTP implementations into sensible, developer-friendly packages. It offers easy-to-use APIs by way of Swift actors, simplifying authentication, safe connections, e mail retrieval, and sending.
Apparently, nearly all of SwiftMail’s code was generated by Cursor utilizing its agent mode. With Cursor’s assist, I reached this state in below per week, drastically condensing what would have in any other case taken a number of weeks of guide growth. My position grew to become certainly one of chief architect, director, and sometimes chief roll-backer-to-a-good-state, since Cursor typically went off on tangents and applied options I didn’t want.

Watch the announcement and demo on the YouTube Webcast.
Technical Background
SwiftMail leverages highly effective underlying expertise from Apple’s Swift NIO ecosystem, together with NIO SSL, as a result of trendy IMAP and SMTP require safe encryption.
Particularly, SwiftMail builds upon:
- NIO IMAP: Apple’s IMAP abstraction, which gives foundational IMAP instructions and responses however was initially cumbersome as a consequence of heavy reliance on guarantees.
- NIO SMTP Instance: Apple’s primary SMTP demonstration undertaking, helpful as a place to begin however missing manufacturing readiness.
SwiftMail enhances these with an actor-based concurrency mannequin, providing builders a less complicated async/await interface. The result’s user-friendly API actors—IMAPServer
and SMTPServer
—that encapsulate the complexity of IMAP and SMTP interactions.
Instance Utilization
Please marvel on the simplicity …
Swift IMAP Instance:
import SwiftIMAP
let imapServer = IMAPServer(host: "imap.instance.com", port: 993)
attempt await imapServer.join()
attempt await imapServer.login(username: "person@instance.com", password: "password")
let mailboxInfo = attempt await imapServer.selectMailbox("INBOX")
print("Mailbox has (mailboxInfo.messageCount) messages")
if let latestMessagesSet = mailboxInfo.newest(10) {
let emails = attempt await imapServer.fetchMessages(utilizing: latestMessagesSet)
for (index, e mail) in emails.enumerated() {
print("[(index + 1)] (e mail.debugDescription)")
}
}
attempt await imapServer.logout()
attempt await imapServer.shut()
A command-line executable goal SwiftIMAPCLI
demonstrates Swift IMAP performance, utilizing credentials from a .env
file positioned within the present working listing.
Swift SMTP Instance:
import SwiftSMTP
let smtpServer = SMTPServer(host: "smtp.instance.com", port: 587)
attempt await smtpServer.join()
attempt await smtpServer.authenticate(username: "person@instance.com", password: "password")
let sender = EmailAddress(handle: "sender@instance.com", identify: "Sender Identify")
let recipient = EmailAddress(handle: "recipient@instance.com", identify: "Recipient Identify")
let e mail = E mail(
sender: sender,
recipients: [recipient],
topic: "Hi there from SwiftSMTP",
physique: "This can be a take a look at e mail despatched utilizing SwiftSMTP."
)
attempt await smtpServer.sendEmail(e mail)
attempt await smtpServer.disconnect()
Equally, there’s a command-line executable goal SwiftSMTPCLI
demonstrating Swift SMTP performance, configured utilizing credentials from a .env
file within the present working listing.
SwiftMail logs all community visitors at hint log stage, which is especially helpful for debugging. The included CLI demos ahead Swift Log messages to OSLog, which you’ll be able to view conveniently in Console.app, categorized by IMAP_IN, IMAP_OUT, SMTP_IN, and SMTP_OUT. Allow detailed logging by setting the setting variable ENABLE_DEBUG_OUTPUT=1
.
Future Plans
My imaginative and prescient for SwiftMail is intently tied to AgentCorp, my AI agent framework. Finally, brokers will draft, modify, and ship emails seamlessly, imitating real-world workflows. SwiftMail is open-source, actively maintained, and welcomes neighborhood contributions and suggestions.
GitHub: https://github.com/Cocoonetics/SwiftMail
Associated
Classes: Elements