Created
November 8, 2018 16:23
-
-
Save siliconvallaeys/2285d31cc62fe64d38f565bba178663e to your computer and use it in GitHub Desktop.
Use SendGrid's API to send emails from Bing Ads Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main() { | |
// Get your own SendGrid API Key from https://app.sendgrid.com/settings/api_keys | |
var SENDGRID_API_KEY='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'; | |
var emailTo = "example@example.com"; | |
var subject = "About your Bing Ads account"; | |
var emailBody = "Now you can send emails using Bing As Scripts. Thanks Optmyzr for the code sample!"; | |
var headers = { | |
"Authorization" : "Bearer "+SENDGRID_API_KEY | |
} | |
var email = {"personalizations": [{"to": [{"email": emailTo}]}],"from": {"email": "sendeexampexample@example.com"},"subject": subject,"content": [{"type": "text/plain", "value": emailBody}]}; | |
var options = { | |
contentType: 'application/json', | |
'muteHttpExceptions': true, | |
'method':'post', | |
'headers':headers, | |
'payload':JSON.stringify(email) | |
} | |
Logger.log(JSON.stringify(options)); | |
var response = UrlFetchApp.fetch('https://api.sendgrid.com/v3/mail/send', options); | |
Logger.log(response.getContentText()); | |
Logger.log(response.getResponseCode()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment