Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Writing Google Apps Script code to automatically send email
Post Body

Hello everyone. I'm trying to write some Apps Script code, which should follow the following pseuo-instructions and achieve the outcome:

  1. Check if there is at least one email with a given label (named 'EmailLabel') in my Gmail account; and
  2. If so, send a pre-written email ('My text.') to all email contacts of a given label (named 'ContactsGroup') in my Google Contacts.

I'm a novice, but I've researched some basics of Apps Script and, after multiple failed attempts, asked Google Gemini to write some code for me. It yielded this result:

function checkAndSendEmail() {

const labelName = 'EmailLabel';

const groupName = 'ContactsGroup';

const emailBody = 'My text.';

const threads = GmailApp.search('EmailLabel:' labelName);

if (threads.length === 1) {

const groupMembers = ContactsApp.getGroupByName(groupName).getContacts();

groupMembers.forEach(member => {

const emailAddress = member.getEmails()[0].getAddress();

MailApp.sendEmail(emailAddress, 'Subject of your email', emailBody);

});

}

}

I executed the code with test data, and the console stated that the execution completed without errors, but the emails did not send.

Is anyone able to please suggest what may be wrong? Thank you in advance!

Author
Account Strength
50%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
129
Link Karma
124
Comment Karma
5
Profile updated: 4 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 months ago