Skip to content
✉️ SMTP protocol support for the Vapor web framework.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Sources/Smtp
Tests
.gitignore
.travis.yml
Package.swift
README.md

README.md

Smtp

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

✉️ 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:

  • Vapor provider/service
  • SwiftNIO Support
  • Text/HTML
  • Attachments
  • SSL
  • Multiple recipients & CC
  • Reply to
  • Multiple emails sent at the same time
  • BCC fields
  • TSL

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
    ...
}
You can’t perform that action at this time.