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.
Hello everyone. I'm trying to write some Apps Script code, which should follow the following pseuo-instructions and achieve the outcome:
- Check if there is at least one email with a given label (named 'EmailLabel') in my Gmail account; and
- 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!
Subreddit
Post Details
- Posted
- 5 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...