fix: Resend welcome email without placeholders (#36772)
parent
4f1e315573
commit
92e30b4c48
@ -0,0 +1,5 @@ |
||||
--- |
||||
"@rocket.chat/meteor": patch |
||||
--- |
||||
|
||||
Fix issue where resending the welcome email could include unresolved placeholders (e.g., `[name]`, `[email]`). |
||||
@ -1,43 +0,0 @@ |
||||
import { Users } from '@rocket.chat/models'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import * as Mailer from '../../app/mailer/server/api'; |
||||
import { settings } from '../../app/settings/server'; |
||||
import { isSMTPConfigured } from '../../app/utils/server/functions/isSMTPConfigured'; |
||||
|
||||
export async function sendWelcomeEmail(to: string): Promise<void> { |
||||
if (!isSMTPConfigured()) { |
||||
throw new Meteor.Error('error-email-send-failed', 'SMTP is not configured', { |
||||
method: 'sendWelcomeEmail', |
||||
}); |
||||
} |
||||
|
||||
const email = to.trim(); |
||||
|
||||
const user = await Users.findOneByEmailAddress(email, { projection: { _id: 1 } }); |
||||
|
||||
if (!user) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { |
||||
method: 'sendWelcomeEmail', |
||||
}); |
||||
} |
||||
|
||||
try { |
||||
let html = ''; |
||||
Mailer.getTemplate('Accounts_UserAddedEmail_Email', (template) => { |
||||
html = template; |
||||
}); |
||||
|
||||
await Mailer.send({ |
||||
to: email, |
||||
from: settings.get('From_Email'), |
||||
subject: settings.get('Accounts_UserAddedEmail_Subject'), |
||||
html, |
||||
}); |
||||
} catch (error: any) { |
||||
throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${error.message}`, { |
||||
method: 'sendWelcomeEmail', |
||||
message: error.message, |
||||
}); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue