mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 06:47:25 +00:00
fix: Resend welcome email without placeholders (#36772)
This commit is contained in:
parent
4f1e315573
commit
92e30b4c48
5
.changeset/mighty-clouds-run.md
Normal file
5
.changeset/mighty-clouds-run.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@rocket.chat/meteor": patch
|
||||
---
|
||||
|
||||
Fix issue where resending the welcome email could include unresolved placeholders (e.g., `[name]`, `[email]`).
|
||||
@ -32,7 +32,6 @@ import { UserChangedAuditStore } from '../../../../server/lib/auditServerEvents/
|
||||
import { i18n } from '../../../../server/lib/i18n';
|
||||
import { removeOtherTokens } from '../../../../server/lib/removeOtherTokens';
|
||||
import { resetUserE2EEncriptionKey } from '../../../../server/lib/resetUserE2EKey';
|
||||
import { sendWelcomeEmail } from '../../../../server/lib/sendWelcomeEmail';
|
||||
import { registerUser } from '../../../../server/methods/registerUser';
|
||||
import { requestDataDownload } from '../../../../server/methods/requestDataDownload';
|
||||
import { resetAvatar } from '../../../../server/methods/resetAvatar';
|
||||
@ -56,6 +55,7 @@ import { generateUsernameSuggestion } from '../../../lib/server/functions/getUse
|
||||
import { saveCustomFields } from '../../../lib/server/functions/saveCustomFields';
|
||||
import { saveCustomFieldsWithoutValidation } from '../../../lib/server/functions/saveCustomFieldsWithoutValidation';
|
||||
import { saveUser } from '../../../lib/server/functions/saveUser';
|
||||
import { sendWelcomeEmail } from '../../../lib/server/functions/saveUser/sendUserEmail';
|
||||
import { setStatusText } from '../../../lib/server/functions/setStatusText';
|
||||
import { setUserAvatar } from '../../../lib/server/functions/setUserAvatar';
|
||||
import { setUsernameWithValidation } from '../../../lib/server/functions/setUsername';
|
||||
@ -66,6 +66,7 @@ import { notifyOnUserChange, notifyOnUserChangeAsync } from '../../../lib/server
|
||||
import { generateAccessToken } from '../../../lib/server/methods/createToken';
|
||||
import { deleteUserOwnAccount } from '../../../lib/server/methods/deleteUserOwnAccount';
|
||||
import { settings } from '../../../settings/server';
|
||||
import { isSMTPConfigured } from '../../../utils/server/functions/isSMTPConfigured';
|
||||
import { getURL } from '../../../utils/server/getURL';
|
||||
import { API } from '../api';
|
||||
import { getPaginationItems } from '../helpers/getPaginationItems';
|
||||
@ -634,7 +635,22 @@ API.v1.addRoute(
|
||||
{
|
||||
async post() {
|
||||
const { email } = this.bodyParams;
|
||||
await sendWelcomeEmail(email);
|
||||
|
||||
if (!isSMTPConfigured()) {
|
||||
throw new MeteorError('error-email-send-failed', 'SMTP is not configured', {
|
||||
method: 'sendWelcomeEmail',
|
||||
});
|
||||
}
|
||||
|
||||
const user = await Users.findOneByEmailAddress(email.trim(), { projection: { name: 1 } });
|
||||
|
||||
if (!user) {
|
||||
throw new MeteorError('error-invalid-user', 'Invalid user', {
|
||||
method: 'sendWelcomeEmail',
|
||||
});
|
||||
}
|
||||
|
||||
await sendWelcomeEmail({ ...user, email });
|
||||
|
||||
return API.v1.success();
|
||||
},
|
||||
|
||||
@ -28,7 +28,7 @@ export async function sendUserEmail(subject: string, html: string, userData: Sav
|
||||
html,
|
||||
data: {
|
||||
email: userData.email,
|
||||
password: userData.password,
|
||||
password: userData.password ?? '******',
|
||||
...(typeof userData.name !== 'undefined' ? { name: userData.name } : {}),
|
||||
},
|
||||
};
|
||||
@ -45,10 +45,10 @@ export async function sendUserEmail(subject: string, html: string, userData: Sav
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendWelcomeEmail(userData: SaveUserData) {
|
||||
export async function sendWelcomeEmail(userData: Pick<SaveUserData, 'email' | 'name' | 'password'>) {
|
||||
return sendUserEmail(settings.get('Accounts_UserAddedEmail_Subject'), html, userData);
|
||||
}
|
||||
|
||||
export async function sendPasswordEmail(userData: SaveUserData) {
|
||||
export async function sendPasswordEmail(userData: Pick<SaveUserData, 'email' | 'name' | 'password'>) {
|
||||
return sendUserEmail(settings.get('Password_Changed_Email_Subject'), passwordChangedHtml, userData);
|
||||
}
|
||||
|
||||
@ -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
Block a user