1

Someone was kind enough a while ago to share with me a script that allowed me to send myself an email automatically as long as I had a time trigger. Yesterday, Google changed the OAuth in Apps Script and it doesn't work anymore. I was wondering if someone may teach me how to update the script I have been using.

Google Changes to OAuth in Apps Script: http://googleappsdeveloper.blogspot.com/2015/03/changes-to-oauth-in-apps-script.html

Below is the script I have been using:

///////////////

function readCell() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Overview");  
  var value = sheet.getRange("D2").getValue();
  if(value>=10) sendEmail(value);
};

function sendEmail(value) {
  var email = "ENTERYOUREMAILHERE";
  var subject = "Vanguard Target Allocation Alert: " + value+"%";
  var body = "This is an automatically generated email to inform you that your Vanguard accounts off of your target allocation by " + value + "%";

  var oauthConfig = UrlFetchApp.addOAuthService("google");
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://spreadsheets.google.com/feeds/");
  oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oauthConfig.setConsumerKey("anonymous");
  oauthConfig.setConsumerSecret("anonymous");
  MailApp.sendEmail(email,subject,body); 

};

///////////////
1

You do not need OAuth for sending a simple mail from Google Script. You remove the deprecated part from your script and it should continue to work.

function sendEmail(value) {

  var email = "ENTERYOUREMAILHERE";
  var subject = "Vanguard Target Allocation Alert: " + value+"%";
  var body = "This is an automatically generated email to inform you that your Vanguard accounts off of your target allocation by " + value + "%";

  MailApp.sendEmail(email,subject,body); 

};
  • Amit, I forgot to update this when I figured it out a few days ago; I did it exactly like you did! I appreciate it, thank you. – Tyler Durden Jul 10 '15 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.