Swiftpack.co - Package - vapor-community/sendgrid-provider

SendGrid Provider for Vapor

Swift Vapor CircleCI

Adds a mail backend for SendGrid to the Vapor web framework. Send simple emails, or leverage the full capabilities of SendGrid's V3 API.

Setup

Add the dependency to Package.swift:

.package(url: "https://github.com/vapor-community/sendgrid-provider.git", from: "3.0.0")

Register the config and the provider.

let config = SendGridConfig(apiKey: "SG.something")

services.register(config)

try services.register(SendGridProvider())

app = try Application(services: services)

sendGridClient = try app.make(SendGridClient.self)

Using the API

You can use all of the available parameters here to build your SendGridEmail Usage in a route closure would be as followed:

import SendGrid

let email = SendGridEmail(…)
let sendGridClient = try req.make(SendGridClient.self)

try sendGridClient.send([email], on: req.eventLoop)

Error handling

If the request to the API failed for any reason a SendGridError is thrown and has an errors property that contains an array of errors returned by the API. Simply ensure you catch errors thrown like any other throwing function

do {
    try sendgridClient.send(...)
}
catch let error as SendGridError {
    print(error)
}

Github

link
Stars: 36
Help us keep the lights on

Dependencies

Releases

3.0.5 - Jun 22, 2018

Improved compatibility with Swift 4.2. Thanks @rafiki270!

3.0.4 - Jun 5, 2018

3.0.3 - May 7, 2018

Supports Vapor official 3.0.0 tag

3.0.2 - Apr 13, 2018

Updates for HTTP parsing.

3.0.1 - Apr 8, 2018

Fixed issues with content type.