Forum Documentation Showcase Pricing Learn more

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

#1

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:

15 Likes

Brainstorming | Sending emails using "Rich Text Input"
#2

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

1 Like

#3

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!

3 Likes

#4

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

1 Like

#5

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!

1 Like

#6

thank you

0 Likes

#7

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

Thanks in advance!

0 Likes

#8

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.

1 Like

#9

@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.

1 Like