I will have a google sheet, which will contain a c...

생성일: 2025년 9월 14일

답변에 사용된 모델 GPT-5 Thinking by 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:-

Subject: Exclusive Invitation - Visit Alica Technologies at Electronica 2025 Bangalore

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: []
  • 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:

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;

text
if (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.

사고

Providing Google Sheet instructions

I need to give thorough instructions on setting up the Google Sheet and provide the complete Google Apps Script code to send emails with inline image embedding. The email should include personalization (like first name) and embed the image inline, not as an attachment. I'll focus on ensuring the format remains as requested while covering how to use GmailApp.sendEmail and DriveApp.getFileById to add the image.

Providing Email Sending Instructions

I’ll provide a code snippet that includes constants for STALL, PHONE, IMAGE_ID, and SHEET_NAME, and give clear instructions on setting Gmail quotas and batching. I’ll avoid asking clarifying questions. The email will use the ‘email’ and ‘firstname’ columns, and include an optional ‘sent’ status. I'll also ensure proper HTML formatting, line breaks, and clickable links. The code will support both plain text and HTML content.

Google Sheet Setup and Email Quotas

I’ll provide instructions for creating a Google Sheet with columns ‘email’, ‘firstname’, and possibly ‘sent’ or ‘error’. I’ll mention steps to fill the rows, get the image file ID from Drive, and set an image variable. I’ll add rate limiting with Utilities.sleep(500) to prevent email bursts. Regarding Gmail quotas, I'll mention the daily limits (100 for free Gmail, 1500 for Workspace) but avoid quoting exact numbers, as they may vary.

Email Setup with Inline Image

I'll include an optional "CC" field as requested and ensure the inline image appears properly within the email body, not as an attachment. I'll use inlineImages for this. I'll propose using Apps Script's HTML service for template creation, while keeping it simple. To handle edge cases, I'll add a check for blank rows, manage header case-sensitivity, and define a helper function to validate columns. I'll also include functions like sendAll() and sendOne(row), along with logging for clarity.

Crafting Invitation Email Code

I’m creating code that uses constants for email details, including the subject, event dates, and stall info. When composing the email, I’ll ensure the body mirrors the format exactly as requested and add placeholders like [] for certain fields. I’ll use inline images and simple HTML formatting. I'll also handle edge cases like blank fields and ensure everything is correctly logged, with status marked as ‘SENT’ after sending. The code won't rely on external tools, only GmailApp.

Thought for 32s

답변

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.

1) Set up your Google Sheet

Create a sheet named Sheet1 with this header row (A1 → C1):

  • email (required)
  • firstname (optional; not used in the greeting since you want “Hello,” exactly)
  • status (auto-filled by the script so you can re-run safely)

Then paste your contacts starting on row 2.

2) Put your image in Google Drive

Upload the image you want to embed to Google Drive.

  • Right-click the image → Get link (any setting is fine for Apps Script).
  • Copy the File ID from the URL (the long string between /d/ and /view).

3) Add the Apps Script

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 => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[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(); }

How it works (and why the image is inline)

  • The message is sent with both htmlBody and a plain-text fallback.
  • The image is passed via inlineImages and referenced in the HTML as <img src="cid:inviteBanner">. This makes it render in the body rather than as a download attachment.
  • A status column is updated to SENT <timestamp> after each success, so you can re-run the script without resending to the same people.
  • Fill CONFIG.STALL, CONFIG.PHONE, and CONFIG.IMAGE_FILE_ID. If PHONE is empty, its line disappears automatically.
  • If you want to CC/BCC yourself, add 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.

이 Q&A 공유하기