Skip to content

vapor-community/sendgrid-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

avatar

SendGridKit

Documentation Team Chat MIT License Continuous Integration Swift 6.0+

📧 SendGridKit is a Swift package that helps you communicate with the SendGrid API in your Server Side Swift applications.

Send simple emails or leverage the full capabilities of SendGrid's V3 API.

Getting Started

Use the SPM string to easily include the dependendency in your Package.swift file

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

and add it to your target's dependencies:

.product(name: "SendGridKit", package: "sendgrid-kit"),

Overview

Register the config and the provider.

import AsyncHTTPClient
import SendGridKit

let httpClient = HTTPClient(...)
let sendGridClient = SendGridClient(httpClient: httpClient, apiKey: "YOUR_API_KEY")

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 SendGridKit

let email = SendGridEmail(...)
try await sendGridClient.send(email: email)

Error handling

If the request to the API failed for any reason a SendGridError is thrown, which 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.

import SendGridKit

do {
    try await sendGridClient.send(email: email)
} catch let error as SendGridError {
    print(error)
}