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.
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' }
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' });
Need help? Contact PubNub Support.
Copyright (c) 2018 PubNub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.