The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/lib/server/methods/sendInvitationEmail.js

51 lines
1.2 KiB

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import * as Mailer from '../../../mailer';
import { hasPermission } from '../../../authorization';
import { settings } from '../../../settings';
let html = '';
Meteor.startup(() => {
Mailer.getTemplate('Invitation_Email', (value) => {
html = value;
});
});
Meteor.methods({
sendInvitationEmail(emails) {
check(emails, [String]);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'sendInvitationEmail',
});
}
if (!hasPermission(Meteor.userId(), 'bulk-register-user')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'sendInvitationEmail',
});
}
const validEmails = emails.filter(Mailer.checkAddressFormat);
const subject = settings.get('Invitation_Subject');
return validEmails.filter((email) => {
try {
return Mailer.send({
to: email,
from: settings.get('From_Email'),
subject,
html,
data: {
email,
},
});
} catch ({ message }) {
throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${ message }`, {
method: 'sendInvitationEmail',
message,
});
}
});
},
});