Button to test SMTP settings;

No need to reload server for SMTP settings to take effect;
Closes #1246
Checks SMTP Settings in #1492
pull/1786/head^2
Marcelo Schmidt 10 years ago
parent f757e25f2b
commit 147ce2d626
  1. 3
      i18n/en.i18n.json
  2. 2
      packages/rocketchat-lib/package.js
  3. 29
      packages/rocketchat-lib/server/methods/sendSMTPTestEmail.coffee
  4. 8
      packages/rocketchat-lib/server/startup/settings.coffee
  5. 25
      packages/rocketchat-lib/server/startup/settingsOnLoadSMTP.coffee

@ -420,6 +420,7 @@
"Select_service_to_login" : "Select a service to login to load your picture or upload one directly from your computer",
"Selected_users" : "Selected members",
"Send" : "Send",
"Send_a_test_mail_to_my_user" : "Send a test mail to my user",
"Send_a_test_push_to_my_user" : "Send a test push to my user",
"Send_confirmation_email" : "Send confirmation email",
"Send_data_into_RocketChat_in_realtime" : "Send data into Rocket.Chat in real-time.",
@ -446,6 +447,7 @@
"SMTP_Host" : "SMTP Host",
"SMTP_Password" : "SMTP Password",
"SMTP_Port" : "SMTP Port",
"SMTP_Test_Button" : "Test SMTP Settings",
"SMTP_Username" : "SMTP Username",
"Sound" : "Sound",
"Start_of_conversation" : "Start of conversation",
@ -558,5 +560,6 @@
"You_will_not_be_able_to_recover" : "You will not be able to recover this message!",
"Your_entry_has_been_deleted" : "Your entry has been deleted.",
"Your_Open_Source_solution" : "Your own Open Source chat solution",
"Your_mail_was_sent_to_s" : "Your mail was sent to %s",
"Your_push_was_sent_to_s_devices" : "Your push was sent to %s devices"
}

@ -69,6 +69,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/saveSetting.coffee', 'server');
api.addFiles('server/methods/sendInvitationEmail.coffee', 'server');
api.addFiles('server/methods/sendMessage.coffee', 'server');
api.addFiles('server/methods/sendSMTPTestEmail.coffee', 'server');
api.addFiles('server/methods/setAdminStatus.coffee', 'server');
api.addFiles('server/methods/setRealName.coffee', 'server');
api.addFiles('server/methods/setUsername.coffee', 'server');
@ -77,6 +78,7 @@ Package.onUse(function(api) {
// SERVER STARTUP
api.addFiles('server/startup/settingsOnLoadCdnPrefix.coffee', 'server');
api.addFiles('server/startup/settingsOnLoadSMTP.coffee', 'server');
api.addFiles('server/startup/oAuthServicesUpdate.coffee', 'server');
api.addFiles('server/startup/settings.coffee', 'server');

@ -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

@ -96,6 +96,7 @@ RocketChat.settings.addGroup 'SMTP', ->
@add 'SMTP_Username', '', { type: 'string', env: true }
@add 'SMTP_Password', '', { type: 'string', env: true }
@add 'From_Email', '', { type: 'string', placeholder: 'email@domain' }
@add 'SMTP_Test_Button', 'sendSMTPTestEmail', { type: 'action', actionText: 'Send_a_test_mail_to_my_user' }
@section 'Invitation', ->
@add 'Invitation_Subject', 'You have been invited to Rocket.Chat', { type: 'string' }
@ -162,13 +163,6 @@ RocketChat.settings.add 'Statistics_opt_out', false, { type: 'boolean', group: f
RocketChat.settings.init()
Meteor.startup ->
if process?.env? and not process.env['MAIL_URL']? and 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'))
# Remove runtime settings (non-persistent)
Meteor.startup ->
RocketChat.models.Settings.update({ ts: { $lt: RocketChat.settings.ts }, persistent: { $ne: true } }, { $set: { hidden: true } }, { multi: true })

@ -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…
Cancel
Save