I will have a google sheet, which will contain a c...
Создано: 14 сентября 2025 г.
Отвечено с использованием GPT-5 Thinking от Chat01
Создано: 14 сентября 2025 г.
Отвечено с использованием GPT-5 Thinking от Chat01
I will have a google sheet, which will contain a column for emails. Then, i have one image which i want to send to all the emails in that sheet.
I have a basic script ready. I want to send the following message to everyone:-
Hello,
We are delighted to extend a personal invitation to visit Alica Technologies LLP at Electronica India 2025, India's premier electronics and embedded systems exhibition.
Event Details
To make the most of your visit, we would be happy to schedule a dedicated meeting at our stall. This will ensure our team can provide you with personalized attention and discuss how our solutions can benefit your organization.
To schedule your visit, please reply to this email or contact:
We look forward to welcoming you at our stall and exploring potential synergies between our organizations.
Thank you for your time, and we hope to see you at Electronica 2025 Bangalore!
Warm regards,
Website: www.alicatechnologies.com
Email: [email protected]
Basic Script:-
function sendPersonalized() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Sheet1'); // change if needed
const rows = sheet.getRange(2,1,sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
const headers = sheet.getRange(1,1,1,sheet.getLastColumn()).getValues()[0];
const emailCol = headers.indexOf('email');
const nameCol = headers.indexOf('firstname'); // optional
for (let i=0;i<rows.length;i++){
const row = rows[i];
const to = row[emailCol];
const first = row[nameCol] || '';
const subject = Your subject here
;
const body = Hi ${first},\n\nThis is the message body.\n\nRegards,\nYour Company
;
textif (to) { GmailApp.sendEmail(to, subject, body, {name: 'Your Company'}); Utilities.sleep(500); // small pause to avoid bursts }
}
}
How should i create the google sheet and write the complete code too. THis format will stay as is. THere is only one image which we need to send along with this email, and it should render in the mail and not like an attachment.
Got you. Here’s a clean, copy-paste setup that keeps your wording exactly as-is, sends one inline image (not as a download/attachment), and pulls addresses from your Google Sheet.
Create a sheet named Sheet1 with this header row (A1 → C1):
Then paste your contacts starting on row 2.
Upload the image you want to embed to Google Drive.
/d/
and /view
).In the Sheet: Extensions → Apps Script → replace everything with this and save.
javascript/***** CONFIG *****/ const CONFIG = { SHEET_NAME: 'Sheet1', SUBJECT: 'Exclusive Invitation - Visit Alica Technologies at Electronica 2025 Bangalore', SENDER_NAME: 'Alica Technologies LLP', REPLY_TO: '[email protected]', // Fill these (you can leave blank; the line will collapse if Phone is blank) STALL: '', // e.g. 'A5-117' PHONE: '', // e.g. '+91 98xxxxxxx' // REQUIRED: paste your Drive image file ID here IMAGE_FILE_ID: 'PUT_DRIVE_FILE_ID_HERE', IMAGE_CID: 'inviteBanner', // referenced inside the HTML via cid: }; /***** MAIN ENTRY *****/ function sendInvites() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheetByName(CONFIG.SHEET_NAME); if (!sheet) throw new Error(`Sheet "${CONFIG.SHEET_NAME}" not found.`); const lastRow = sheet.getLastRow(); const lastCol = sheet.getLastColumn(); if (lastRow < 2) { Logger.log('No data rows found.'); return; } const headers = sheet.getRange(1, 1, 1, lastCol).getValues()[0].map(h => String(h).trim().toLowerCase()); const idx = { email: headers.indexOf('email'), firstname: headers.indexOf('firstname'), status: headers.indexOf('status'), }; if (idx.email === -1) throw new Error('Missing required header "email".'); if (idx.status === -1) throw new Error('Missing header "status". Please add a "status" column.'); const rows = sheet.getRange(2, 1, lastRow - 1, lastCol).getValues(); const imgBlob = DriveApp.getFileById(CONFIG.IMAGE_FILE_ID).getBlob(); let sentCount = 0; for (let r = 0; r < rows.length; r++) { const row = rows[r]; const to = String(row[idx.email] || '').trim(); const already = String(row[idx.status] || '').toUpperCase().startsWith('SENT'); if (!to || already) continue; const { html, text } = buildBodies({ firstname: idx.firstname !== -1 ? (row[idx.firstname] || '') : '', stall: CONFIG.STALL, phone: CONFIG.PHONE, }); try { GmailApp.sendEmail( to, CONFIG.SUBJECT, text, // fallback for plain-text clients { htmlBody: html, inlineImages: { [CONFIG.IMAGE_CID]: imgBlob }, name: CONFIG.SENDER_NAME, replyTo: CONFIG.REPLY_TO, } ); sheet.getRange(r + 2, idx.status + 1).setValue(`SENT ${new Date()}`); sentCount++; Utilities.sleep(400); // gentle pacing } catch (e) { sheet.getRange(r + 2, idx.status + 1).setValue(`ERROR: ${e.message}`); Logger.log(`Failed for ${to}: ${e}`); } } Logger.log(`Done. Sent ${sentCount} email(s).`); } /***** OPTIONAL: quick self test *****/ function sendTestToMe() { const me = Session.getActiveUser().getEmail(); const imgBlob = DriveApp.getFileById(CONFIG.IMAGE_FILE_ID).getBlob(); const { html, text } = buildBodies({ firstname: '', stall: CONFIG.STALL, phone: CONFIG.PHONE }); GmailApp.sendEmail( me, `[TEST] ${CONFIG.SUBJECT}`, text, { htmlBody: html, inlineImages: { [CONFIG.IMAGE_CID]: imgBlob }, name: CONFIG.SENDER_NAME, replyTo: CONFIG.REPLY_TO, } ); Logger.log('Sent test to your account email.'); } /***** TEMPLATE (keeps your exact wording/format) *****/ function buildBodies({ firstname, stall, phone }) { // Keep greeting EXACT (no name inserted), per your request. const phoneLine = phone ? `\n- Phone: ${escapeHtml(phone)}` : ''; const stallText = stall ? stall : '[]'; // Plain-text version (fallback) const text = `Hello, We are delighted to extend a personal invitation to visit Alica Technologies LLP at Electronica India 2025, India's premier electronics and embedded systems exhibition. Event Details - Event: Electronica 2025 Bangalore - Our Stall: ${stallText} - Dates: 17th - 19th September 2025 To make the most of your visit, we would be happy to schedule a dedicated meeting at our stall. This will ensure our team can provide you with personalized attention and discuss how our solutions can benefit your organization. To schedule your visit, please reply to this email or contact: - Email: [email protected] , [email protected]${phoneLine} We look forward to welcoming you at our stall and exploring potential synergies between our organizations. Thank you for your time, and we hope to see you at Electronica 2025 Bangalore! Warm regards, Website: www.alicatechnologies.com Email: [email protected]`; // HTML version (with inline image) const html = `<div style="font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:1.6;color:#111;"> <img src="cid:${CONFIG.IMAGE_CID}" alt="Alica Technologies – Electronica 2025" style="max-width:100%;height:auto;display:block;margin:0 0 16px 0;"> <p>Hello,</p> <p>We are delighted to extend a personal invitation to visit <strong>Alica Technologies LLP</strong> at Electronica India 2025, India's premier electronics and embedded systems exhibition.</p> <p><strong>Event Details</strong><br> - Event: <strong>Electronica 2025 Bangalore</strong><br> - Our Stall: <strong>${escapeHtml(stallText)}</strong><br> - Dates: <strong>17th - 19th September 2025</strong></p> <p>To make the most of your visit, we would be happy to schedule a dedicated meeting at our stall. This will ensure our team can provide you with personalized attention and discuss how our solutions can benefit your organization.</p> <p>To schedule your visit, please reply to this email or contact:<br> - Email: <a href="mailto:[email protected]">[email protected]</a> , <a href="mailto:[email protected]">[email protected]</a><br> ${phone ? `- Phone: ${escapeHtml(phone)}<br>` : ''}</p> <p>We look forward to welcoming you at our stall and exploring potential synergies between our organizations.</p> <p>Thank you for your time, and we hope to see you at Electronica 2025 Bangalore!</p> <p>Warm regards,</p> <p>Website: <a href="https://www.alicatechnologies.com">www.alicatechnologies.com</a><br> Email: <a href="mailto:[email protected]">[email protected]</a></p> </div>`; return { html, text }; } /***** UTIL *****/ function escapeHtml(str) { return String(str).replace(/[&<>"]/g, s => ({'&':'&','<':'<','>':'>','"':'"'}[s])); } /***** (Optional) Custom menu in the Sheet *****/ function onOpen() { SpreadsheetApp.getUi() .createMenu('Bulk Email') .addItem('Send Invites', 'sendInvites') .addItem('Send Test To Me', 'sendTestToMe') .addToUi(); }
inlineImages
and referenced in the HTML as <img src="cid:inviteBanner">
. This makes it render in the body rather than as a download attachment.SENT <timestamp>
after each success, so you can re-run the script without resending to the same people.CONFIG.STALL
, CONFIG.PHONE
, and CONFIG.IMAGE_FILE_ID
. If PHONE
is empty, its line disappears automatically.bcc: '[email protected]'
in the sendEmail
options.If you want me to tweak any detail (add a logo link, auto-fill stall, send in batches, etc.), say the word and I’ll drop it straight in.