# fastify-sendgrid

> Sendgrid Mail for Fastify

Latest version **1.0.4** (published 2022-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-sendgrid
pnpm add fastify-sendgrid
yarn add fastify-sendgrid
bun add fastify-sendgrid
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-07-15 |
| First published | 2022-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Marcio Zebedeu |
| Maintainers | zebedeu |
| Keywords | fastify-sendgrid, @sendgrid/mail, sendgrid, mail |

## Links

- npm: https://www.npmjs.com/package/fastify-sendgrid
- Repository: https://github.com/Zebedeu/fastify-sendgrid
- Homepage: https://github.com/Zebedeu/fastify-sendgrid#readme
- Issues: https://github.com/Zebedeu/fastify-sendgrid/issues
- npm.io page: https://npm.io/package/fastify-sendgrid

## Dependencies (2)

- [@sendgrid/mail](https://npm.io/package/@sendgrid/mail.md) ^7.7.0
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^3.0.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2022-07-15
- 1.0.3 — 2022-07-02
- 1.0.2 — 2022-07-02
- 1.0.1 — 2022-07-02
- 1.0.0 — 2022-07-02

## README

# fastify-mail

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
[![Version](https://img.shields.io/npm/v/fastify-sendgrid.svg)](https://www.npmjs.com/package/fastify-sendgrid)


## Install
```
npm i fastify-sendgrid --save
```
```
yarn add fastify-sendgrid
```

## Versions

The plugin supports the following `Fastify` and `sendgrid/mail` versions. Please refer to corresponding branch in PR and issues.

version | branch | fastify | sendgrid/mail | End of support
--------|--------|---------|------------|---------------  
1.x | [maain](https://github.com/Zebedeu/fastify-sendgrid | 4.x | ^7.7.0 |   

## Usage
Add it to you project with `register` and you are done!
You can access  via `fastify.sendgrid` and *send()* via `fastify.sendgrid.send()`. and `reply.sendgrid.send()`.

```js
const fastify = require('fastify')()

fastify.register(require('fastify-sendgrid'), {
  apiKey: ""
})

fastify.get('/sendmail/:email', (req, reply, next) => {
  let { sendgrid } = fastify
  let recipient = req.params.email

 const msg = {
        to: recipient,
        from: 'example@gmail.com', // Use the email address or domain you verified above
        subject: 'Sending with Twilio SendGrid is Fun',
        text: 'and easy to do anywhere, even with Node.js',
        html: '<strong>and easy to do anywhere, even with Node.js</strong>',
      };
      //ES6
      sendgrid
        .send(msg)
        .then(() => {}, error => {
          console.error(error);
      
          if (error.response) {
            console.error(error.response.body)
          }
        });
      //ES8
      (async () => {
        try {
          await sendgrid.send(msg);
        } catch (error) {
          console.error(error);
      
          if (error.response) {
            console.error(error.response.body)
          }
        }
      })();
})

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})
```

## License

Licensed under [MIT](./LICENSE).

---
_Source: https://npm.io/package/fastify-sendgrid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
