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/packages/rocketchat-lib/server/methods/sendInvitationEmail.coffee

42 lines
1.7 KiB

Meteor.methods
sendInvitationEmail: (emails) ->
check emails, [String]
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', "Invalid user", { method: 'sendInvitationEmail' }
unless RocketChat.authz.hasRole(Meteor.userId(), 'admin')
throw new Meteor.Error 'error-not-allowed', "Not allowed", { method: 'sendInvitationEmail' }
rfcMailPattern = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
validEmails = _.compact _.map emails, (email) -> return email if rfcMailPattern.test email
header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || "")
footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || "")
if RocketChat.settings.get('Invitation_Customized')
subject = RocketChat.settings.get('Invitation_Subject')
html = RocketChat.settings.get('Invitation_HTML')
else
subject = TAPi18n.__('Invitation_Subject_Default', { lng: Meteor.user()?.language || RocketChat.settings.get('language') || 'en' })
html = TAPi18n.__('Invitation_HTML_Default', { lng: Meteor.user()?.language || RocketChat.settings.get('language') || 'en' })
subject = RocketChat.placeholders.replace(subject);
for email in validEmails
@unblock()
html = RocketChat.placeholders.replace(html, { email: email });
try
Email.send
to: email
from: RocketChat.settings.get 'From_Email'
subject: subject
html: header + html + footer
catch error
throw new Meteor.Error 'error-email-send-failed', 'Error trying to send email: ' + error.message, { method: 'sendInvitationEmail', message: error.message }
return validEmails