> For the complete documentation index, see [llms.txt](https://openai.gitbook.io/code-cheatsheets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openai.gitbook.io/code-cheatsheets/all/apis/sendgrid.md).

# Sendgrid

Go through the setup flow to get API\_KEY

## Node

utils.js

```javascript
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(conf.get("SENDGRID_API_KEY"));
module.exports = {sgMail};
```

router/user.js

```javascript
const { sgMail } = require("../utils.js");

const msg = {
  to: "jsjfuentesj@gmail.com",
  from: {
    email: "friends.modulo@gmail.com",
    name: "Team Modulo"
  },
  dynamic_template_data: {
    article_link: req.body.url
  },
  template_id: "d-256323a1409f4afc8e1fa85682b248b3"
};
await sgMail.send(msg);
```

## [Elixir](https://hexdocs.pm/sendgrid/SendGrid.Email.html)

mix.exs

```elixir
{:sendgrid, "~> 2.0"}
```

config.exs

```elixir
config :sendgrid,
  api_key: "SENDGRID_API_KEY"
```

reactphoenix/email.ex

```elixir
defmodule ReactPhoenix.Email do
  alias SendGrid.Email
  alias SendGrid.Mail

  def test() do
    Email.build()
    |> Email.add_to("jsjfuentesj@gmail.com")
    |> Email.put_from("test@slingshow.com")
    |> Email.put_subject("Hello from Elixir")
    |> Email.put_text("Sent with Elixir")
    |> Mail.send()
  end
end
```
