Starklytech Newsletter Script Code Copy

function sendNewsletter() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var startRow = 2; // Skip the header row var numRows = sheet.getLastRow() - 1; // Number of rows with data var batchSize = 10; // Number of emails to send per batch var maxEmailsPerDay = 500; // Daily limit var maxEmailsPerWeek = 3500; // Weekly limit var maxRetries = 5; // Maximum number of retries for exponential backoff var dataRange = sheet.getRange(startRow, 1, numRows, 1); // Only one column needed var data = dataRange.getValues(); var scriptProperties = PropertiesService.getScriptProperties(); // Reset properties for each run scriptProperties.setProperty('LAST_PROCESSED_ROW', startRow - 1); // Start from the beginning scriptProperties.setProperty('EMAILS_SENT_TODAY', 0); // Reset daily count scriptProperties.setProperty('EMAILS_SENT_THIS_WEEK', 0); // Reset weekly count scriptProperties.setProperty('LAST_RUN_DATE', new Date()); // Update last run date var lastProcessedRow = parseInt(scriptProperties.getProperty('LAST_PROCESSED_ROW')) || startRow - 1; var emailsSentToday = parseInt(scriptProperties.getProperty('EMAILS_SENT_TODAY')) || 0; var emailsSentThisWeek = parseInt(scriptProperties.getProperty('EMAILS_SENT_THIS_WEEK')) || 0; var emailsSent = 0; // Count emails sent in this session // HTML email template const htmlContent = ` Get the latest updates from StarklyTech – your source for all things mobile tech.
Blog Logo

| Your Go-To Guide For Mobile
Tech

Home | Top Picks | Phone Gear | Tech Tips | Deals

Top Story of the Week

Featured Article Image

The Latest Breakthrough in Mobile Technology

By John Doe | August 28, 2024

Read More

Latest Blog Posts

Post 1 Image

5 Ways to Improve Your Smartphone Photography

Discover the top tips to enhance your photos and capture stunning moments...

Read More
Post 2 Image

The Future of 5G: What You Need to Know

Understand how 5G technology is set to revolutionize mobile communications...

Read More
Post 3 Image

Top 10 Tech Gadgets of 2024

A roundup of the must-have tech gadgets of the year, perfect for any enthusiast...

Read More
Post 4 Image

Understanding AI in Mobile Apps

Explore how AI is transforming mobile applications, making them smarter...

Read More
Post 5 Image

Smartphone Security: Tips and Tricks

Learn the best practices to secure your smartphone from potential threats...

Read More
Post 6 Image

Virtual Reality: The Next Big Thing in Mobile Gaming

Discover how virtual reality is set to change the landscape of mobile gaming...

Read More
Advertisement

Stay Connected with Us

Facebook X (formerly Twitter) Instagram YouTube Pinterest TikTok
Visit Our Website

© 2024 StarklyTech. All rights reserved.

You are receiving this email because you subscribed to receive newsletters and promotional materials from Starklytech.com. Unsubscribe | Update Preferences

`; for (var i = lastProcessedRow + 1; i < startRow + numRows; i++) { // Fix here if (emailsSentToday >= maxEmailsPerDay || emailsSentThisWeek >= maxEmailsPerWeek) { Logger.log('Daily or weekly email limit reached.'); break; } var emailAddress = data[i - startRow][0]; // First column holds the email address try { MailApp.sendEmail({ to: emailAddress, subject: 'Essential maintenance tips for your mobile device', htmlBody: htmlContent, name: 'StarklyTech' }); emailsSent++; emailsSentToday++; emailsSentThisWeek++; scriptProperties.setProperty('LAST_PROCESSED_ROW', i); scriptProperties.setProperty('EMAILS_SENT_TODAY', emailsSentToday); scriptProperties.setProperty('EMAILS_SENT_THIS_WEEK', emailsSentThisWeek); Utilities.sleep(500); // Delay to avoid hitting email sending rate limits } catch (e) { Logger.log('Failed to send email to: ' + emailAddress + '. Error: ' + e.toString()); // Implement retry logic with exponential backoff var retryCount = 0; while (retryCount < maxRetries) { try { Utilities.sleep(Math.pow(2, retryCount) * 1000); // Exponential backoff MailApp.sendEmail({ to: emailAddress, subject: 'Essential maintenance tips for your mobile device', htmlBody: htmlContent, name: 'StarklyTech' }); emailsSent++; emailsSentToday++; emailsSentThisWeek++; scriptProperties.setProperty('LAST_PROCESSED_ROW', i); scriptProperties.setProperty('EMAILS_SENT_TODAY', emailsSentToday); scriptProperties.setProperty('EMAILS_SENT_THIS_WEEK', emailsSentThisWeek); break; } catch (e) { retryCount++; Logger.log('Retry ' + retryCount + ' failed for email to: ' + emailAddress); } } } } Logger.log('Emails sent: ' + emailsSent); }