function createAndSendFlyer() {
// Create a new Google Doc named 'Coders for Liberty flyer'
var doc = DocumentApp.create('Coders for Liberty flyer');
// Access the body of the document, then add paragraphs.
doc.getBody().setFontFamily('Roboto Mono');
doc.getBody().appendParagraph('Join us at http://code4liberty.wordpress.com');
doc.getBody().setLinkUrl('http://code4liberty.wordpress.com');
doc.getBody().appendParagraph('Have you ever wanted to write a program');
doc.getBody().appendParagraph('but you thought it was too difficult?');
doc.getBody().appendParagraph('Programming is not out of your reach.')
doc.getBody().appendParagraph('Programming is like any other skill.');
doc.getBody().appendParagraph('It takes practice, persistence,');
doc.getBody().appendParagraph('and the will to succeed.');
doc.getBody().appendParagraph('The question is not if you can write a program');
doc.getBody().appendParagraph('but what you want your program to do.');
doc.getBody().appendParagraph('The key to programming is creativity
doc.getBody().appendParagraph('and imagination.');
doc.getBody().appendParagraph('And the persistence to learn');
doc.getBody().appendParagraph('the syntax of the languages.');
doc.getBody().appendParagraph('Free yourself from the shackles of your own doubts.');
// Get the URL of the document.
var url = doc.getUrl();
// Get the email address of the active user - that's you.
var email = Session.getActiveUser().getEmail();
// Get the name of the document to use as an email subject line.
var subject = doc.getName();
// Append a new string to the "url" variable to use as an email body.
var body = 'Link to your doc: ' + url;
// Send yourself an email with a link to the document.
GmailApp.sendEmail(email, subject, body);
}
function majorParty() {
// candidate that I support
var iSupport = "Kudos";
// candidate that I oppose
var iOppose = "Kang";
// body of email
// third party candidates
var thirdParty = ["A third party candidate", "Another third party candidate"];
// names of email recipients
var name = ["Cody Liberty", "Cody"]
// email addresses of email recipients
var email = ["code4liberty@gmail.com", "code4liberty@gmail.com"]
// loop through email addresses
for (j = 0; j < name.length; j++) {
var message = "";
message = message.concat("Dear ", name[j], ":\n\n")
// cylce through third party candidates
for (i = 0; i < thirdParty.length; i++)
{
message = message.concat("It does not matter that ", thirdParty[i]);
message = message.concat(" is not ", iOppose);
message = message.concat("."," ");
} // close 3rd party loop
message = message.concat("What matters is that ", iSupport);
message = message.concat(" is not ", iOppose);
message = message.concat("! Therefore you must support ", iSupport);
message = message.concat("! ", iSupport);
message = message.concat(" is the only one that is not ");
message = message.concat(iOppose, " that can win because people like me support ");
message = message.concat(iSupport, "! It does not matter how ");
message = message.concat(iSupport, " stands on the issues. Let's jump off this cliff together! ");
message = message.concat("Who cares what your mom told you when you were a kid! That does not matter now! We cannot allow ", iOppose);
message = message.concat(" to win!");
message = message.concat("\n\nSincerely,\n", iSupport, " against ", iOppose);
message = message.concat("\n\nThis is a joke. No one paid me to do this.");
message = message.concat(" I am just practicing my coding skills on stupid");
message = message.concat(" political nonsense. Don't vote for anyone! ");
message = message.concat("They're all bat excrement crazy!");
// Get the email address of the active user - that's you.
//var email = Session.getActiveUser().getEmail();
// Subject line
var subject = "We cannot allow ".concat(iOppose, " to win! You must vote for ");
subject = subject.concat(iSupport, "!!!");
// Send yourself an email with a link to the document.
GmailApp.sendEmail(email[j], subject, message);
} // close loop
} // close function
function sendEmails() {
// these top four variable are what you may need to change.
// string from url and share link
targetId = '1fgBuVkM1rk9oZ8tjbwi1UrNFDfElpG2zw2qfj_VJpm8';
var count = 2; // number of emails;
var ecol = 'A'; // column with emails
var ncol = 'B'; // column with names
var yourName = "Punkbass"; // name of person sending email.
// should not need to change these
var sheet = SpreadsheetApp.openById(targetId);
var emails = new Array(count); // emails
var names = new Array(count);
var ecell = ''; // email cell
var ncell = ''; // name cell
// cycle through cells to get emails and names
for (i = 0; i < (count); i++) {
ecell = ecol.concat(i+2);
ncell = ncol.concat(i+2);
emails[i] = sheet.getRange(ecell).getValue();
names[i] = sheet.getRange(ncell).getValue();
}
// send the emails
for (i=0; i < names.length; i++) {
var subject = "Coders for Liberty";
// salutations
var message = "Dear ".concat(names[i], ":\n\n");
// body
var message = message.concat("Thank you for joining coders for liberty.");
// signature
var message = message.concat("\n\nSincerely,\n", yourName);
MailApp.sendEmail(emails[i], subject, message);
}
}
You will want to make a new Google Sheet to test this out on. Something like this:
| email address | name |
| you@gmail.com | Cody |
| you@gmail.com | Sam |
targetId = '1fgBuVkM1rk9oZ8tjbwi1UrNFDfElpG2zw2qfj_VJpm8';
And change yourName to your name. And you might want to change the body of the message to something with more substance. And if you're using an existing spreadsheet with the email and name in different columns, just change the ecol and ncol variables to the columns in your spreadsheet. That might be easier to do than changing the spreadsheet itself.
Note: Normally you would not want to create an array using the new command. At least that is what w3School says. Normally, you would use brackets like a Python list:
var theArrayName = [element1, element2, element3];If you do this:
var theArrayName = new Array(2);You make an array with 2 elements. But that's the way I wanted to make my array. I wanted an array with count elements. That's the only reason I used new. If you decide to use the while loop, I would recommend using the [ ] method and the .push() method.