diff --git a/mailer.js b/mailer.js index 0efb429..a6534ca 100644 --- a/mailer.js +++ b/mailer.js @@ -1,4 +1,6 @@ const nodemailer = require('nodemailer'); +const fs = require('fs'); +const path = require('path'); /** * Sends a premium custom email with the PDF attachment. @@ -22,12 +24,24 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer) => { const orderNumber = orderData.order_number || orderData.name; const currencySymbol = orderData.currency === 'INR' ? 'Rs. ' : `${orderData.currency} `; + + // Load logo as base64 so it always displays in Gmail (no external URL blocking) + const localLogoPath = path.join(__dirname, 'logo.png'); + let logoBase64 = ''; + let logoMimeType = 'image/png'; + if (fs.existsSync(localLogoPath)) { + logoBase64 = fs.readFileSync(localLogoPath).toString('base64'); + } // --- 1. Generate Order Summary Rows HTML --- let orderRowsHtml = ''; if (orderData.line_items && orderData.line_items.length > 0) { orderData.line_items.forEach(item => { - const itemImageUrl = item.image || (item.featured_image && item.featured_image.url) || ''; + // Shopify stores product image under item.image (object with src) or item.featured_image.url + const itemImageUrl = (item.image && item.image.src) + || (item.image && typeof item.image === 'string' ? item.image : '') + || (item.featured_image && item.featured_image.url) + || ''; const imageHtml = itemImageUrl ? ` ${item.title} @@ -110,7 +124,7 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer) => {
- rayaarishop + rayaarishop Order #${orderNumber}