Swiftpack.co - Package - Mikroservices/Smtp

Smtp

Build Status Swift 5.0 Vapor 3 Swift Package Manager Platforms OS X | Linux

:email: SMTP protocol support for the Vapor web framework.

This framework has dependencies only to Vapor and SwiftNIO packages. SwiftNIO support was inspired by Apple examples: Swift NIO examples.

Features:

  • [x] Vapor provider/service
  • [x] SwiftNIO Support
  • [x] Text/HTML
  • [x] Attachments
  • [x] SSL/TLS (when connection starts)
  • [x] STARTTSL support
  • [x] Multiple recipients & CC
  • [x] Reply to
  • [ ] BCC fields
  • [ ] Multiple emails sent at the same time

Getting started

Add the dependency to Package.swift:

.package(url: "https://github.com/Mikroservices/Smtp.git", from: "1.0.0")

Register the SMTP server configuration and the provider.

let configuration = SmtpServerConfiguration(hostname: "smtp.server",
                                            port: 465,
                                            username: "johndoe",
                                            password: "passw0rd",
                                            secure: .ssl)

services.register(configuration)
try services.register(SmtpClientProvider())

Using SMTP client.

let smtpClientService = try app.make(SmtpClientService.self)

let email = Email(from: EmailAddress(address: "john.doe@testxx.com", name: "John Doe"),
                  to: [EmailAddress(address: "ben.doe@testxx.com", name: "Ben Doe")],
                  subject: "The subject (text)",
                  body: "This is email body.")

smtpClientService.send(email, on: request).map { result in
    switch result {
    case .success:
        print("Email has been sent")
    case .failure(let error):
        print("Email has not been sent: \(error)")
    }  
}

Troubleshoots

You can use logHandler to handle and print all messages send/retrieved from email server.

smtpClientService.send(email, on: request) { message in
    print(message)
}.map { result in
    ...
}

Github

link
Stars: 0
Help us keep the lights on

Used By

Total:

Releases

1.1.0 - Apr 25, 2019

This release includes support of STARTTLS command (and further encryption).

1.0.0 - Apr 16, 2019

Features:

  • Vapor provider/service
  • SwiftNIO Support
  • Text/HTML
  • Attachments
  • SSL