No need to reload server for SMTP settings to take effect; Closes #1246 Checks SMTP Settings in #1492pull/1786/head^2
parent
f757e25f2b
commit
147ce2d626
@ -0,0 +1,29 @@ |
||||
Meteor.methods |
||||
sendSMTPTestEmail: -> |
||||
if not Meteor.userId() |
||||
throw new Meteor.Error 'invalid-user', "[methods] sendSMTPTestEmail -> Invalid user" |
||||
|
||||
user = Meteor.user() |
||||
unless user.emails?[0]?.address |
||||
throw new Meteor.Error 'invalid-email', "[methods] sendSMTPTestEmail -> Invalid e-mail" |
||||
|
||||
Email.send |
||||
to: user.emails[0].address |
||||
from: RocketChat.settings.get('From_Email') |
||||
subject: "SMTP Test E-mail" |
||||
html: "You have successfully sent an e-mail" |
||||
|
||||
console.log 'Sending email to ' + user.emails[0].address |
||||
|
||||
return { |
||||
message: "Your_mail_was_sent_to_s" |
||||
params: [user.emails[0].address] |
||||
} |
||||
|
||||
# Limit a user to sending 1 test mail/second |
||||
DDPRateLimiter.addRule |
||||
type: 'method' |
||||
name: 'sendSMTPTestEmail' |
||||
userId: (userId) -> |
||||
return true |
||||
, 1, 1000 |
@ -0,0 +1,25 @@ |
||||
buildMailURL = _.debounce -> |
||||
console.log 'Updating process.env.MAIL_URL' |
||||
if RocketChat.settings.get('SMTP_Host') and RocketChat.settings.get('SMTP_Username') and RocketChat.settings.get('SMTP_Password') |
||||
process.env.MAIL_URL = "smtp://" + encodeURIComponent(RocketChat.settings.get('SMTP_Username')) + ':' + encodeURIComponent(RocketChat.settings.get('SMTP_Password')) + '@' + encodeURIComponent(RocketChat.settings.get('SMTP_Host')) |
||||
if RocketChat.settings.get('SMTP_Port') |
||||
process.env.MAIL_URL += ':' + parseInt(RocketChat.settings.get('SMTP_Port')) |
||||
, 500 |
||||
|
||||
RocketChat.settings.onload 'SMTP_Host', (key, value, initialLoad) -> |
||||
if _.isString value |
||||
buildMailURL() |
||||
|
||||
RocketChat.settings.onload 'SMTP_Port', (key, value, initialLoad) -> |
||||
buildMailURL() |
||||
|
||||
RocketChat.settings.onload 'SMTP_Username', (key, value, initialLoad) -> |
||||
if _.isString value |
||||
buildMailURL() |
||||
|
||||
RocketChat.settings.onload 'SMTP_Password', (key, value, initialLoad) -> |
||||
if _.isString value |
||||
buildMailURL() |
||||
|
||||
Meteor.startup -> |
||||
buildMailURL() |
Loading…
Reference in new issue