Skip to content

T2Je/VaporSMTPKit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vapor 4 + SMTP

Add this library to Package.swift

.package(url: "https://github.com/autimatisering/VaporSMTPKit.git", from: "1.0.0")

Add the target "VaporSMTPKit" to your own target's dependencies. In Swift 5.2 manifests, this looks like the following:

.product(name: "VaporSMTPKit", package: "VaporSMTPKit"),

Setup

import VaporSMTPKit

extension SMTPCredentials {
    static var `default`: SMTPCredentials {
        return SMTPCredentials(
            hostname: "smtp.example.com",
            ssl: .startTLS(configuration: .default),
            email: "[email protected]",
            password: "<SECRET>"
        )
    }
}

Sending a Mail

app.get { request -> EventLoopFuture<String> in
    let email = Mail(
        from: "[email protected]",
        to: [
            MailUser(name: "Myself", email: "[email protected]")
        ],
        subject: "Your new mail server!",
        contentType: .plain,
        text: "You've set up mail!"
    )
    
    return request.application.sendMail(email, withCredentials: .default).map { 
        return "Check your mail!"
    }
}

About

SMTP support in Vapor 4

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%