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/apps/meteor/app/api/server/v1/mailer.ts

42 lines
940 B

import { isMailerProps, isMailerUnsubscribeProps } from '@rocket.chat/rest-typings';
import { API } from '../api';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
API.v1.addRoute(
'mailer',
{
authRequired: true,
validateParams: isMailerProps,
},
{
async post() {
if (!(await hasPermissionAsync(this.userId, 'send-mail'))) {
throw new Error('error-not-allowed');
}
const { from, subject, body, dryrun, query } = this.bodyParams;
const result = await Meteor.callAsync('Mailer.sendMail', from, subject, body, Boolean(dryrun), query);
return API.v1.success(result);
},
},
);
API.v1.addRoute(
'mailer.unsubscribe',
{
authRequired: true,
validateParams: isMailerUnsubscribeProps,
},
{
async post() {
const { _id, createdAt } = this.bodyParams;
await Meteor.callAsync('Mailer:unsubscribe', _id, createdAt);
return API.v1.success();
},
},
);