Lightweight SMTP client built on top of SwiftNIO.
[
]
(https://github.com/BinaryBirds/swift-nio-smtp/releases/tag/1.0.0-beta.1
)
- Async SMTP client build over SwiftNIO
- STARTTLS and SSL support
- AUTH LOGIN
- Raw DATA payload support
- No Foundation framework dependency
- Swift 6.1+
- Platforms:
- macOS 15+
- iOS 18+
- tvOS 18+
- watchOS 11+
- visionOS 2+
Use Swift Package Manager; add the dependency to your Package.swift file:
.package(url: "https://github.com/BinaryBirds/swift-nio-smtp", exact: "1.0.0-beta.1"),Then add NIOSMTP to your target dependencies:
.product(name: "NIOSMTP", package: "swift-nio-smtp"),API documentation is available at the following link.
Create an SMTPEnvelope with a raw DATA payload and send it using NIOSMTP.
import NIOSMTP
import NIO
import Logging
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let smtp = NIOSMTP(
eventLoopGroup: eventLoopGroup,
configuration: .init(
hostname: "smtp.example.com",
signInMethod: .credentials(
username: "user@example.com",
password: "app-password"
)
),
logger: .init(label: "nio-smtp")
)
let raw = [
"From: sender@example.com",
"To: recipient@example.com",
"Subject: Hello",
"Date: Mon, 01 Jan 2024 00:00:00 +0000",
"Message-ID: <message@example.com>",
"Content-Type: text/plain; charset=\"UTF-8\"",
"Mime-Version: 1.0",
"",
"Hello from SwiftNIO SMTP.",
""
].joined(separator: "\r\n")
let envelope = try SMTPEnvelope(
from: "sender@example.com",
recipients: ["recipient@example.com"],
data: raw
)
try await smtp.send(envelope)
try await eventLoopGroup.shutdownGracefully()- Build:
swift build - Test:
- local:
make test - using Docker:
make docker-test
- local:
- Format:
make format - Check:
make check
Pull requests are welcome. Please keep changes focused and include tests for new logic.
The NIOSMTP library is heavily inspired by Mikroservices/Smtp.