An experimental SMTP client, written in Swift and based on SwiftNIO 2.
Works on macOS, iOS and Linux.
⚠️ Untested against most SMTP server software.⚠️ Untested against most email clients.- Seems to work for some very specific use-cases.
- Don't use it in production; you will likely regret it!
In Package.swift:
// in your package:
dependencies: [
.package(url: "https://github.com/andreasley/SimpleSMTPClient.git", branch: "master")
]
// in your target:
dependencies: [
.product(name: "SimpleSMTPClient", package: "SimpleSMTPClient")
]),
In Xcode: Adding package dependencies to your app
import SimpleSMTPClient
let server = SMTPServerConfiguration(
hostname: "someSmtpServerHost.com",
port: .defaultForTLS,
security: .TLS,
authentication: .login(username: "someUsername", password: "somePassword")
)
let email = Email()
email.subject = "Hello there!"
email.from = "[email protected]"
email.to = ["[email protected]"]
email.htmlBody = "<html><body><h1>Email attachment test</h1></body></html>"
let textAttachment = try Attachment(filename: "test.txt", data: "hello".data(using: .utf8)!, contentType: "text/plain")
email.attachments.append(textAttachment)
let mailer = Mailer(server: server)
try mailer.send(email: email) { result in
switch result {
case .success(_):
print("✅")
case .failure(let error):
print("❌ : \(error)")
}
}
Feel free to fork (see license) or contribute.
Partially based on https://github.com/apple/swift-nio-examples/tree/master/NIOSMTP