0

How can I send email using a transactional email template with SendGrid.

I am using the email package from meteorjs and I am able to send simple emails through

  Email.send({
    from: "myemail@gmail.com",
    to: "somebodyelses.email@gmail.com",
    subject: "A sample subject",
    text: "Here is some text."
  });

I can't find meteorjs packages either.

Mark Pazon
  • 6,167
  • 2
  • 34
  • 50

1 Answers1

4

Have you configured the email package with the correct host name and credentials? You can see an example on the SendGrid blog. Once you've got the server configured properly and you can send simple emails, then you can add to Email.headers an X-SMTPAPI header. Then you can use transactional templates via the X-SMTPAPI header.

It will look something like this:

Email.send({
  from: "myemail@gmail.com",
  to: "somebodyelses.email@gmail.com",
  subject: "A sample subject",
  text: "Here is some text.",
  headers: {"X-SMTPAPI": '{
      "filters": {
        "templates": {
          "settings": {
            "enable": 1,
            "template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f"
          }
        }
      }
    }'
  }
});
bwest
  • 9,182
  • 3
  • 28
  • 58
  • Wow! Thanks! Adding the `headers` did the trick. However, I am receiving everything in plaintext. Meaning the images are gone, and the text are not formatted. Any clue? – Mark Pazon Mar 25 '16 at 17:50
  • Ok got it to work by adding `"Content-Type" : "text/html"` to `headers`. – Mark Pazon Mar 25 '16 at 18:01
  • I think this is because your `html` parameter is not set in the `Email.send` call. Setting it to something random worked for me as well. – Rijk Jan 09 '17 at 19:49
  • @MarkPazon Its sending only simple text email for me even after adding "Content-Type" : "text/html" . https://stackoverflow.com/questions/47217847/trigger-sendgrid-template-email-using-meteor Any help? – Abid Iqbal Nov 10 '17 at 10:45