SendGrid: Transactional Emails with Templates

Send transactional emails with your custom templates triggered by user action.

In order to use this Function, first setup a custom designed template in the SendGrid Transactional Template creator and read our full SendGrid and PubNub Tutorial here. To send your first automated email, simply send a PubNub Publish message from your application. Once sent, the PubNub Function will POST to SendGrid and send the email that you customized. Additionally, substitutions for template variables can be set in your PubNub Function.

Setup

  1. Login or Register to Admin Portal

  2. Select Functions

  3. Select your desired App and Keyset

  4. Select "Explore Templates" and proceed with selected integration.

Walkthrough

To learn how to send your first automated email through SendGrid, read our full SendGrid Transactional Template Tutorial here. To send your first automated email with SendGrid and PubNub, simply replace the template_id in the PubNub Function with the one defined in the Templates tool in the SendGrid portal. Next, add your SendGrid API Key to the PubNub Vault by clicking on the My Secrets button in the PubNub Functions editor. In the Test Payload window and/or your PubNub Publish message, the to field defines what email address the automated email will be sent to, and the toname field defines the receivers first and last name. In the PubNub Function, the xhr.fetch call sends all of the information about the sender to SendGrid so the email can be sent.

{
    'toname': 'Full Name',
    'to': 'EmailAddress@gmail.com'
}

Example

To send an email from your PubNub powered application, simply send a Pubnub Publish from your Application to the channel name defined in your PubNub Function.

1

Talk to an expert