GithubHelp home page GithubHelp logo

sendgrid's Introduction

SendGrid Provider for Vapor

Continuous Integration Swift 5.2

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.git", from: "4.0.0")

Make sure SENDGRID_API_KEY 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.

Optionally, explicitly initialize the provider (this is strongly recommended, as otherwise a missing API key will cause a fatal error some time later in your application):

app.sendgrid.initialize()

Now you can access the client at any time:

app.sendgrid.client

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()

try await req.application.sendgrid.client.send(email)

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:

do {
		try await req.application.sendgrid.client.send(email)
} catch let error as SendGridError {
		req.logger.error("\(error)")
}

sendgrid's People

Contributors

0xtim avatar andrewangeta avatar anthonycastelli avatar bygri avatar gwynne avatar jdmcd avatar jseibert avatar melgu avatar proggeramlug avatar rafiki270 avatar riichard avatar vzsg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.