Skip to content

steffendsommer/VaporMailgunService

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vapor Mailgun Service

Slack Platforms Swift 4.1 Vapor 3

Mailgun is a Vapor 3 service for a popular email sending API

Installation

Vapor Mailgun Service can be installed with Swift Package Manager

.package(url: "https://github.com/twof/VaporMailgunService.git", from: "0.4.0")

Usage

Sign up and set up a Mailgun account here

Make sure you get an API key and register a custom domain

Configure

In configure.swift:

let mailgun = Mailgun(apiKey: "<api key>", domain: "mg.example.com")
services.register(mailgun, as: Mailgun.self)

Use

In routes.swift:

router.post("mail") { (req) -> Future<Response> in
    let message = Mailgun.Message(
        from: "postmaster@example.com",
        to: "example@gmail.com",
        subject: "Newsletter",
        text: "This is a newsletter",
        html: "<h1>This is a newsletter</h1>"
    )
    
    let mailgun = try req.make(Mailgun.self)
    return try mailgun.send(message, on: req)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%