debugged some stuff
This commit is contained in:
parent
dfe244f821
commit
ba246d5dc8
@ -532,6 +532,7 @@ class CampaignsController {
|
|||||||
|
|
||||||
// Send email if SMTP method
|
// Send email if SMTP method
|
||||||
if (emailMethod === 'smtp') {
|
if (emailMethod === 'smtp') {
|
||||||
|
console.log('DEBUG: About to send campaign email...');
|
||||||
emailResult = await emailService.sendCampaignEmail(
|
emailResult = await emailService.sendCampaignEmail(
|
||||||
recipientEmail,
|
recipientEmail,
|
||||||
userEmail,
|
userEmail,
|
||||||
@ -543,9 +544,11 @@ class CampaignsController {
|
|||||||
recipientName,
|
recipientName,
|
||||||
recipientLevel
|
recipientLevel
|
||||||
);
|
);
|
||||||
|
console.log('DEBUG: Campaign email service returned:', emailResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the campaign email
|
// Log the campaign email
|
||||||
|
console.log('DEBUG: About to log campaign email with emailResult:', emailResult);
|
||||||
await nocoDB.logCampaignEmail({
|
await nocoDB.logCampaignEmail({
|
||||||
campaign_id: campaign.ID || campaign.Id || campaign.id,
|
campaign_id: campaign.ID || campaign.Id || campaign.id,
|
||||||
campaign_slug: slug,
|
campaign_slug: slug,
|
||||||
@ -561,6 +564,7 @@ class CampaignsController {
|
|||||||
message: message,
|
message: message,
|
||||||
status: emailMethod === 'mailto' ? 'clicked' : (emailResult.success ? 'sent' : 'failed')
|
status: emailMethod === 'mailto' ? 'clicked' : (emailResult.success ? 'sent' : 'failed')
|
||||||
});
|
});
|
||||||
|
console.log('DEBUG: Campaign email logged with status:', emailMethod === 'mailto' ? 'clicked' : (emailResult.success ? 'sent' : 'failed'));
|
||||||
|
|
||||||
if (emailMethod === 'smtp') {
|
if (emailMethod === 'smtp') {
|
||||||
if (emailResult.success) {
|
if (emailResult.success) {
|
||||||
|
|||||||
@ -92,28 +92,40 @@ class EmailService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('DEBUG: About to send email via SMTP...');
|
||||||
const info = await this.transporter.sendMail(mailOptions);
|
const info = await this.transporter.sendMail(mailOptions);
|
||||||
|
|
||||||
console.log('Email sent successfully:', info.messageId);
|
console.log('DEBUG: Email sent via SMTP successfully:', info.messageId);
|
||||||
|
console.log('DEBUG: Email info response:', info.response);
|
||||||
|
|
||||||
// Log email to database if NocoDB service is available
|
// Log email to database if NocoDB service is available
|
||||||
await this.logEmailSent({
|
console.log('DEBUG: About to log email to database...');
|
||||||
to: emailOptions.to, // Log original recipient
|
try {
|
||||||
subject: emailOptions.subject, // Log original subject
|
await this.logEmailSent({
|
||||||
status: 'sent',
|
to: emailOptions.to, // Log original recipient
|
||||||
messageId: info.messageId,
|
subject: emailOptions.subject, // Log original subject
|
||||||
testMode: testMode,
|
status: 'sent',
|
||||||
senderName: emailOptions.from?.name || 'System',
|
messageId: info.messageId,
|
||||||
senderEmail: emailOptions.from?.email || process.env.SMTP_FROM_EMAIL
|
testMode: testMode,
|
||||||
});
|
senderName: emailOptions.from?.name || 'System',
|
||||||
|
senderEmail: emailOptions.from?.email || process.env.SMTP_FROM_EMAIL
|
||||||
|
});
|
||||||
|
console.log('DEBUG: Successfully logged email to database');
|
||||||
|
} catch (logError) {
|
||||||
|
console.error('DEBUG: Failed to log email to database:', logError);
|
||||||
|
// Continue anyway - don't let logging failure affect email success
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
const successResult = {
|
||||||
success: true,
|
success: true,
|
||||||
messageId: info.messageId,
|
messageId: info.messageId,
|
||||||
response: info.response,
|
response: info.response,
|
||||||
testMode: testMode,
|
testMode: testMode,
|
||||||
originalRecipient: testMode ? emailOptions.to : undefined
|
originalRecipient: testMode ? emailOptions.to : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('DEBUG: Returning success result:', successResult);
|
||||||
|
return successResult;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Email send error:', error);
|
console.error('Email send error:', error);
|
||||||
|
|
||||||
@ -218,9 +230,12 @@ class EmailService {
|
|||||||
|
|
||||||
// Template-based email methods
|
// Template-based email methods
|
||||||
async sendTemplatedEmail(templateName, templateVariables, emailOptions, isTest = false) {
|
async sendTemplatedEmail(templateName, templateVariables, emailOptions, isTest = false) {
|
||||||
|
console.log('DEBUG: sendTemplatedEmail called with template:', templateName);
|
||||||
try {
|
try {
|
||||||
// Render the template
|
// Render the template
|
||||||
|
console.log('DEBUG: About to render template...');
|
||||||
const { html, text } = await emailTemplates.render(templateName, templateVariables);
|
const { html, text } = await emailTemplates.render(templateName, templateVariables);
|
||||||
|
console.log('DEBUG: Template rendered successfully');
|
||||||
|
|
||||||
// Prepare email options with rendered content
|
// Prepare email options with rendered content
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
@ -230,9 +245,12 @@ class EmailService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Send the email using existing sendEmail method
|
// Send the email using existing sendEmail method
|
||||||
return await this.sendEmail(mailOptions, isTest);
|
console.log('DEBUG: About to call sendEmail from sendTemplatedEmail...');
|
||||||
|
const result = await this.sendEmail(mailOptions, isTest);
|
||||||
|
console.log('DEBUG: sendEmail returned result:', result);
|
||||||
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to send templated email:', error);
|
console.error('DEBUG: Failed to send templated email:', error);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: error.message
|
error: error.message
|
||||||
@ -266,6 +284,7 @@ class EmailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async sendCampaignEmail(recipientEmail, userEmail, userName, postalCode, subject, message, campaignTitle, recipientName = null, recipientLevel = null) {
|
async sendCampaignEmail(recipientEmail, userEmail, userName, postalCode, subject, message, campaignTitle, recipientName = null, recipientLevel = null) {
|
||||||
|
console.log('DEBUG: sendCampaignEmail called for recipient:', recipientEmail);
|
||||||
const templateVariables = {
|
const templateVariables = {
|
||||||
MESSAGE: message,
|
MESSAGE: message,
|
||||||
USER_NAME: userName,
|
USER_NAME: userName,
|
||||||
@ -286,7 +305,10 @@ class EmailService {
|
|||||||
subject: subject
|
subject: subject
|
||||||
};
|
};
|
||||||
|
|
||||||
return await this.sendTemplatedEmail('campaign-email', templateVariables, emailOptions);
|
console.log('DEBUG: About to call sendTemplatedEmail from sendCampaignEmail...');
|
||||||
|
const result = await this.sendTemplatedEmail('campaign-email', templateVariables, emailOptions);
|
||||||
|
console.log('DEBUG: sendCampaignEmail received result:', result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendTestEmail(subject, message, testRecipient = null) {
|
async sendTestEmail(subject, message, testRecipient = null) {
|
||||||
@ -364,29 +386,6 @@ class EmailService {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendEmail(emailOptions) {
|
|
||||||
try {
|
|
||||||
if (!this.transporter) {
|
|
||||||
throw new Error('Email transporter not initialized');
|
|
||||||
}
|
|
||||||
|
|
||||||
const mailOptions = {
|
|
||||||
from: `${process.env.SMTP_FROM_NAME || 'BNKops Influence'} <${process.env.SMTP_FROM_EMAIL || 'noreply@example.com'}>`,
|
|
||||||
to: emailOptions.to,
|
|
||||||
subject: emailOptions.subject,
|
|
||||||
text: emailOptions.text,
|
|
||||||
html: emailOptions.html
|
|
||||||
};
|
|
||||||
|
|
||||||
const info = await this.transporter.sendMail(mailOptions);
|
|
||||||
console.log(`Email sent: ${info.messageId}`);
|
|
||||||
return info;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to send email:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new EmailService();
|
module.exports = new EmailService();
|
||||||
Loading…
x
Reference in New Issue
Block a user