Skip to content

Instantly share code, notes, and snippets.

@siliconvallaeys
Created November 8, 2018 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siliconvallaeys/2285d31cc62fe64d38f565bba178663e to your computer and use it in GitHub Desktop.
Save siliconvallaeys/2285d31cc62fe64d38f565bba178663e to your computer and use it in GitHub Desktop.
Use SendGrid's API to send emails from Bing Ads Scripts
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