PubNub Integration

SendGrid: Transactional Emails with Templates

IoT Device Control

IoT Device Control

In-app chat

In-app chat

Last Updated:

2018/10/24

Author:

Jordan Schuetz

SendGrid Documentation

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.

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.

Pubnub.publish({
    message: {
        'toname' : 'FirstName LastName',
        'to' : 'EmailAddress@gmail.com'
    }
    channel: 'email-sendgrid-channel'
});

Feedback & Support

Need help? Contact PubNub Support.


Talk to an expert

Contact Sales