Skip to content

andreasley/SimpleSMTPClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleSMTPClient

An experimental SMTP client, written in Swift and based on SwiftNIO 2.

Supported platforms

Works on macOS, iOS and Linux.

State and compatibility

  • ⚠️ 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!

Usage

Specify the dependendy

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 the module

import SimpleSMTPClient

Configure the server

let server = SMTPServerConfiguration(
    hostname: "someSmtpServerHost.com",
    port: .defaultForTLS,
    security: .TLS,
    authentication: .login(username: "someUsername", password: "somePassword")
)

Create the message

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>"

Add an attachment

let textAttachment = try Attachment(filename: "test.txt", data: "hello".data(using: .utf8)!, contentType: "text/plain")
email.attachments.append(textAttachment)

Send the email

let mailer = Mailer(server: server)
try mailer.send(email: email) { result in
    switch result {
    case .success(_):
        print("")
    case .failure(let error):
        print("❌ : \(error)")
    }
}

Contributing

Feel free to fork (see license) or contribute.

Attribution

Partially based on https://github.com/apple/swift-nio-examples/tree/master/NIOSMTP

About

Experimental cross-platform SMTP client for Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages