https://github.com/vapor-community/sendgrid
📧 SendGrid-powered mail backend for Vapor
https://github.com/vapor-community/sendgrid
email sendgrid server-side-swift swift swift-linux swift-package swift-package-manager vapor vapor-provider vapor-service
Last synced: 3 months ago
JSON representation
📧 SendGrid-powered mail backend for Vapor
- Host: GitHub
- URL: https://github.com/vapor-community/sendgrid
- Owner: vapor-community
- License: mit
- Created: 2017-01-26T05:38:01.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-02-01T15:58:39.000Z (5 months ago)
- Last Synced: 2025-03-29T13:06:17.975Z (3 months ago)
- Topics: email, sendgrid, server-side-swift, swift, swift-linux, swift-package, swift-package-manager, vapor, vapor-provider, vapor-service
- Language: Swift
- Homepage: https://swiftpackageindex.com/vapor-community/sendgrid
- Size: 108 KB
- Stars: 77
- Watchers: 7
- Forks: 31
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
📧 SendGrid library for the Vapor web framework, based on [SendGridKit](https://github.com/vapor-community/sendgrid-kit).
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.git", from: "6.0.0"),
```and add it to your target's dependencies:
```swift
.product(name: "SendGrid", package: "sendgrid"),
```## Overview
> [!WARNING]
> Make sure that the `SENDGRID_API_KEY` variable is set in your environment.
This can be set in the Xcode scheme, or specified in your `docker-compose.yml`, or even provided as part of a `swift run` command.
A missing API key will result in a fatal error.### 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 SendGridlet email = SendGridEmail(…)
try await req.sendgrid.client.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 SendGriddo {
try await req.sendgrid.client.send(email: email)
} catch let error as SendGridError {
req.logger.error("\(error.errors)")
}
```