https://github.com/vapor-community/sendgrid-kit
📧 A Swift on Server SDK for the SendGrid API
https://github.com/vapor-community/sendgrid-kit
email mail sendgrid server-side-swift swift swift-library swift-linux swift-package swift-package-manager
Last synced: about 2 months ago
JSON representation
📧 A Swift on Server SDK for the SendGrid API
- Host: GitHub
- URL: https://github.com/vapor-community/sendgrid-kit
- Owner: vapor-community
- License: mit
- Created: 2019-11-13T17:43:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-29T17:12:27.000Z (5 months ago)
- Last Synced: 2025-04-28T20:59:45.282Z (about 2 months ago)
- Topics: email, mail, sendgrid, server-side-swift, swift, swift-library, swift-linux, swift-package, swift-package-manager
- Language: Swift
- Homepage: https://swiftpackageindex.com/vapor-community/sendgrid-kit
- Size: 47.9 KB
- Stars: 12
- Watchers: 8
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
📧 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](https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send).
### Getting Started
Use the SPM string to easily include the dependendency in your `Package.swift` file
```swift
.package(url: "https://github.com/vapor-community/sendgrid-kit.git", from: "3.0.0"),
```and add it to your target's dependencies:
```swift
.product(name: "SendGridKit", package: "sendgrid-kit"),
```## Overview
Register the config and the provider.
```swift
import AsyncHTTPClient
import SendGridKitlet 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:
```swift
import SendGridKitlet 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.
```swift
import SendGridKitdo {
try await sendGridClient.send(email: email)
} catch let error as SendGridError {
print(error)
}
```