Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.