[Beginners Guide] to Sending Emails With Sendgrid - Work in Progress!

Hey Everyone… I’m on a journey to understand all that can be done with Sendgrid, and I’m going to document my experience here!

The Big Picture
You could say there are three kinds of emails you can send from Bubble…

  1. Bubble’s Transactional Emails
    By this we mean the ones that that Bubble sends out automatically on our user’s behalf such as those for a password reset.

  2. Bubble’s “Send Email” Action
    So using the standard action that comes with native Bubble, found in Add Action -> Email -> Send Email.

  3. Using a Plugin
    Which brings all sorts of other possibilities.

For the sake of this discussion, let’s call (1) and (2) “native emails”, and (3) “plugin emails”.

Native Emails: How Bubble Works By Default.
When you first set up an account with Bubble, native emails are sent via an email service which comes as a part of the Amazon Web Services (AWS) environment that Bubble is hosted on. However that service has some limitations, in terms of the number of emails you can send per day, and the fact that the email header looks like it has come from a “no reply” location (even though you can actually set up a working reply to address ).

To overcome this, Bubble set up an integration with a professional email service called Sendgrid (who have recently been bought by Twilio).

A Quick Overview of Sendgrid
Email systems are based on the idea of defining a Template for the emails they will send. A Template defines the overall look and feel of the email, and the content is then inserted into the template using a kind of [shortcode] system. In Sendgrid these are called Variables, and are enclosed in {{CurlyBraces}}, or <%PercentTags%>.

Bulk emails are generally seen as being for one of two functions: “transactional” emails for things like password resets or telling your client you received their payment, and “marketing” emails for things like newsletters. Transactional emails you tend to send one at a time and can look quite plain. Marketing emails you tend to send en-mass for things like newsletters, and you want them to have more of an eye catching design.

Sendgrid actually has three types of templates, which at first can be a little confusing:

  • Legacy - a basic form of transactional template from their earlier days of operation.
  • Transactional - their more recent and sophisticated transactional templates.
  • Marketing - their marketing email template types.

Setting Up the Sendgrid - The Basics
To move over to sending emails by Sendgrid, you have to go through a potentially confusing setup process which has the possibility of using either Legacy or Transactional templates - hence this setup guide to help you on the way. Note that your Bubble app has to be on a custom domain before you can do all of this.

The first installation stage is the same for either…

  1. Head over to sendgrid.com and set up an account.
  2. Go to Settings -> API Keys, Create an API Key, and copy it.
  3. In Bubble, go to Settings -> Domain/Email, and paste the key into the Sendgrid API Key field.
  4. Click the Connect button next to this field to send Bubble off to check it can talk to Sendgrid okay.

So far so good.

Setting Up Sendgrid - Legacy Templates
The easiest way to set up Sendgrid is with a Legacy Template. So back in Sendgrid:

  1. Go to Templates -> Legacy.
  2. [Create Template]
  3. Give it a name like “Bubble Send Email Template”. Click [Save]
  4. You now get an ID code listed.
  5. Click on [Add Version]. A new window comes sliding out from the side. Select Design Editor and [Continue].
  6. You now come into a whole other template design world. Luckily you don’t need to do much in here!
  7. On the left hand side, Enter into the Template Name field a name like “Bubble Send Email Template v1”.
  8. Click [Save Template] and then the <- back button.
  9. You should now be back on the Legacy Transactional Templates page where your template is listed, along with the ID key. Copy the ID key.

Back in Bubble…

  1. In Settings -> Domain and Email, paste the template id key into the Template ID (optional) field.

Bingo! You should be good to go. Test out sending a password reset email and an email via the action Emails -> Send Email and check everything is working okay.

You will find that the Send Email action now has an option “Do not apply a Sendgrid Template”. I have found whether that is ticked or not, an email is sent. It is possible you can actually send emails without going through the legacy template setup process, but I never got to check that out… and certainly now you have a template, you have some control to change the details of how it looks.

Why Use A Sendgrid Plugin?
So if you can send emails okay as described, why would you want to use a plugin to access Sendgrid? The main reasons for me are:

  1. As my app is multi-user, so my users can send emails that appear to have come from them. The Send Email action in Bubble allows can send emails with a specific “reply-to address” and “email from name”, but it always leave the “email from address” the same, which looks a bit odd.
  2. So I can access details of whether the email was sent back in Bubble, rather than my users needing to go into Sendgrid to find this out.

A plugin will work in parallel with what you have already set up - so your legacy template will work with your “native” email sending, and the plugin with actions you invoke which call it up.

At the time of writing, there is just one Sendgrid plugin for sending emails, which is the “Send Emails With Sendgrid” one created by @copilot.

Using The Send Emails With Sendgrid Plugin
Once installed, the plugin gives you two new actions in the Plugins menu. We will work with the “Sendgrid Send Email” action:

MORE DETAILS TO FOLLOW! :slight_smile:

108 Likes

Great stuff - if only your Beginner guides were around back in my early Bubble days!

5 Likes

Thanks Geoff. When I’m working on something that seems to have so many ways forward my head ends up as spaghetti, so writing it down really helps me as well as hopefully those who follow!

14 Likes

Watching this thread for some more great info on email setup, thanks Antony!

3 Likes

Same here - I’m currently trying to figure out how to send purchase information/notifications to sellers on my app so will be interested to see how this progresses. Thanks for taking a go at this Antony!

3 Likes

thank you

Hello,
Has anyone figured out how to send lists to sendgrid?
Here’s my post on another thread about my issue

Thanks in advance!

Hey @vin… good question! I’ve not tried lists being sent directly to Sendgrid yet, but I will need to some time soon. For the moment, I have my own shortcode generator, so I create an email of the form:

Dear [First Name], here is my message

and then I use an api call on a list of contacts which sends each email separately. I use a find/replace function on the email body to replace [First Name] with the contact’s first name from the database.

Hope this helps!
Best wishes,
Antony.

3 Likes

@antony Well it turns out I was making one very simple mistake.

The values that you are sending to sendgrid need to be in an HTML section…


…but honestly im 99.99999 sure i was doing that the whole time.
Guess not.

moral of the story: double check EVERYTHING.

4 Likes

This is PURE GOLD! Thanks!

2 Likes

Thanks for this!

Would you have any idea how to add new users to a marketing list in Sendgrid? It seems like this can be done during the signup workflow using the API connector. But I’m not really sure.

Thanks!

Hi there @daniel4

Glad you like it! I haven’t got into Sendgrid any more since writing the post, and I’m going to migrate away to Postmark in the next month or so…

… so I’m sorry, I can’t answer your question! Maybe posting it as a separate forum post will get you the answer you need.

Best wishes,
Antony.

1 Like

question, if I setup sendgrid in domain/email tab and send emails thru sendgrid, will I be charged for the emails sent?

Hi, sendgrid is freemium so you get 100 mails per day for free.

What happens after the last free message for the day? Excess emails will not be sent?

1 Like

Thanks so much for writing this, I got it all set up and working very easily thanks to you :smiley:

3 Likes

I don’t see this field.

Hello

Really great guide…I’m still building my application at the moment, so haven’t yet migrated over to a my own custom domain name.

Does this prohibit me from integrating with Send Grid at this stage?

In that case, I may set all emails up using the bubble native email action at the moment, but then migrate all this email activity over to Send Grid once I have set up my application on my own custom domain.

Many thanks!

You can use Zapier and add a trigger to start that zap. I’ve used it and it works perfectly

2 Likes

great thanks - you mean to say that you’ve used zapier to connect “bubble<>send grid” instead of directly integrating bubble with sendgrid through the plugin or via an API?

Appreciate your suggestion :slight_smile: