Sending emails with sendgrid

I am using this library written by @alexgaribay. I have setup the api key in the config . Using the SendGrid Emai and Mailer to send the email .

        Email.build()
      |> Email.add_to("email")
      |> Email.put_from("email")
      |> Email.put_subject("Hello from Elixir")
      |> Email.put_text("Sent with Elixir")
      |> Mailer.send()

This returns :ok. But I am not receiving email in the email address I write in the above Email.add_to . Am I doing some thing wrong?

Have you checked your Spam Folder?

yes.
And also use different emails. Get :ok from the SendGrid but no email.

We are using send grid as well. If nothing else helps you can try this piece of code to send a mail and look if it works: https://gist.github.com/mlankenau/91d450f6ad9edb3cbadbd9aa746b176f
Just to exclude the possibility that there is an issue in the lib.

You have to set SEND_GRID_API_KEY in your env.

1 Like

If :ok is being returned, then SendGrid is saying that it’s a valid request. Do you by chance have the sandbox_enabled flag as true in your config? That would be the only way you’d get :ok without the email being sent.

2 Likes

Thanks alex for your reply. It seems to work fine after deleting deps folder and running mix.deps again.