I am trying to send emails via google app svript but it is not working. please help

128 views
Skip to first unread message

Abhishek Sinha

unread,
Oct 16, 2023, 9:56:26 AM10/16/23
to Google Apps Script Community

I am wrting in google bard the following prompt " Write a google app script to schedule emails from my gmail id to multiple email ids without using api. The email has a subject, three paragraphs and a pdf attachment. The email should be schlude for tommrrow morning at 9 am." Then it is spitting out this code

function sendScheduledEmails() { // Get the email recipients. var recipients = ["recip...@example.com", "recip...@example.com"]; // Create the email message. var emailSubject = "Scheduled email subject"; var emailBody = ` Paragraph 1 Paragraph 2 Paragraph 3 `; // Create a new draft email. var draftEmail = MailApp.createDraftEmail(); draftEmail.setSubject(emailSubject); draftEmail.setBody(emailBody); draftEmail.addTo(recipients); // Attach the PDF file. var pdfFile = Utilities.newBlob("application/pdf", Utilities.readFile("path/to/pdf/file.pdf")); draftEmail.addAttachment(pdfFile, "file.pdf"); // Schedule the email to be sent tomorrow morning at 9 AM. var tomorrowAt9AM = new Date(); tomorrowAt9AM.setDate(tomorrowAt9AM.getDate() + 1); tomorrowAt9AM.setHours(9); tomorrowAt9AM.setMinutes(0); tomorrowAt9AM.setSeconds(0); draftEmail.scheduleSend(tomorrowAt9AM); } // Set up a trigger to run the script tomorrow morning at 9 AM. ScriptApp.newTrigger("sendScheduledEmails").timeTrigger(new Date()).create();

but the issue is that whenever i am running it I am getting the following error:

TypeError: ScriptApp.newTrigger(...).timeTrigger is not a function (anonymous)@ Code.gs:35 TypeError: ScriptApp.newTrigger(...).timeBased(...).everyDays(...).atHour(...).atMinute is not a function (anonymous)@ Code.gs:35 TypeError: MailApp.createDraftEmail is not a function

How do I fix it?

Orville Wright

unread,
Oct 16, 2023, 11:28:46 AM10/16/23
to Google Apps Script Community
Please review "Manage triggers programmatically" at https://developers.google.com/apps-script/guides/triggers/installable.
Reply all
Reply to author
Forward
0 new messages