fix: Embed logo as base64 data URI for Gmail compatibility, fix Shopify product image URL path
This commit is contained in:
parent
aa6afe5612
commit
62a135dc85
18
mailer.js
18
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
|
||||
? `<td style="padding: 15px 0; width: 60px; vertical-align: middle;">
|
||||
<img src="${itemImageUrl}" alt="${item.title}" style="width: 50px; height: 50px; border-radius: 6px; border: 1px solid #e2e8f0; object-fit: cover;" />
|
||||
@ -110,7 +124,7 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer) => {
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td style="font-family: Helvetica, Arial, sans-serif;">
|
||||
<img src="https://cdn.shopify.com/s/files/1/0878/6791/2485/files/logo_150x.png" alt="rayaarishop" style="height: 60px; width: auto; display: block;" />
|
||||
<img src="data:${logoMimeType};base64,${logoBase64}" alt="rayaarishop" style="height: 60px; width: auto; display: block;" />
|
||||
</td>
|
||||
<td align="right" style="font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #94a3b8; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px;">
|
||||
Order #${orderNumber}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user