From dffe3d5ade15582ec71714031509a314a2616667 Mon Sep 17 00:00:00 2001 From: nztqa Date: Mon, 27 Nov 2017 16:44:19 +0900 Subject: [PATCH 1/3] Add test SMTP settings --- client/components/settings/settingBody.jade | 3 +++ client/components/settings/settingBody.js | 11 +++++++++ i18n/en.i18n.json | 1 + models/settings.js | 25 +++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/client/components/settings/settingBody.jade b/client/components/settings/settingBody.jade index 2152cc2ce..479ccd3e4 100644 --- a/client/components/settings/settingBody.jade +++ b/client/components/settings/settingBody.jade @@ -89,6 +89,9 @@ template(name='email') li button.js-save.primary {{_ 'save'}} + li + button.js-send-smtp-test-email.primary {{_ 'send-smtp-test'}} + template(name='accountSettings') ul#account-setting.setting-detail li.smtp-form diff --git a/client/components/settings/settingBody.js b/client/components/settings/settingBody.js index 27f690ee5..c94f46bbd 100644 --- a/client/components/settings/settingBody.js +++ b/client/components/settings/settingBody.js @@ -125,6 +125,16 @@ BlazeComponent.extendComponent({ }, + sendSMTPTestEmail() { + Meteor.call('sendSMTPTestEmail', (err, ret) => { + if (!err && ret) { /* eslint-disable no-console */ + console.log('Success:', ret.message, ret.email); + } else { + console.log('Error: Sending test email', err); + } /* eslint-enable no-console */ + }); + }, + events(){ return [{ 'click a.js-toggle-registration': this.toggleRegistration, @@ -133,6 +143,7 @@ BlazeComponent.extendComponent({ 'click a.js-toggle-board-choose': this.checkBoard, 'click button.js-email-invite': this.inviteThroughEmail, 'click button.js-save': this.saveMailServerInfo, + 'click button.js-send-smtp-test-email': this.sendSMTPTestEmail, }]; }, }).register('setting'); diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 63e5be1c2..11a9eef66 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -386,6 +386,7 @@ "smtp-password": "Password", "smtp-tls": "TLS support", "send-from": "From", + "send-smtp-test": "Send a test mail to my user", "invitation-code": "Invitation Code", "email-invite-register-subject": "__inviter__ sent you an invitation", "email-invite-register-text": "Dear __user__,\n\n__inviter__ invites you to Wekan for collaborations.\n\nPlease follow the link below:\n__url__\n\nAnd your invitation code is: __icode__\n\nThanks.", diff --git a/models/settings.js b/models/settings.js index a02bb3fb6..a05f22725 100644 --- a/models/settings.js +++ b/models/settings.js @@ -141,5 +141,30 @@ if (Meteor.isServer) { } }); }, + + sendSMTPTestEmail() { + if (!Meteor.userId()) { + throw new Meteor.Error('error-invalid-user', 'Invalid user'); + } + const user = Meteor.user(); + if (!user.emails && !user.emails[0] && user.emails[0].address) { + throw new Meteor.Error('error-invalid-email', 'Invalid email'); + } + this.unblock(); + try { + Email.send({ + to: user.emails[0].address, + from: Accounts.emailTemplates.from, + subject: 'SMTP Test Email From Wekan', + text: 'You have successfully sent an email', + }); + } catch ({message}) { + throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${ message }`, message); + } + return { + message: 'email-sent', + email: user.emails[0].address, + }; + }, }); } From 332f12ce2806abcba84eec5b12ea33b26d3a3cd0 Mon Sep 17 00:00:00 2001 From: nztqa Date: Mon, 27 Nov 2017 19:24:06 +0900 Subject: [PATCH 2/3] Add alert method --- client/components/settings/settingBody.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/components/settings/settingBody.js b/client/components/settings/settingBody.js index c94f46bbd..e2d0383f9 100644 --- a/client/components/settings/settingBody.js +++ b/client/components/settings/settingBody.js @@ -129,8 +129,10 @@ BlazeComponent.extendComponent({ Meteor.call('sendSMTPTestEmail', (err, ret) => { if (!err && ret) { /* eslint-disable no-console */ console.log('Success:', ret.message, ret.email); + alert('Success'); } else { console.log('Error: Sending test email', err); + alert(err); } /* eslint-enable no-console */ }); }, From 44559b52a6d45df57f1ca8eeaae25d55eb7e8148 Mon Sep 17 00:00:00 2001 From: nztqa Date: Tue, 28 Nov 2017 13:26:46 +0900 Subject: [PATCH 3/3] Add smtp test email translations --- client/components/settings/settingBody.js | 11 +++++++---- i18n/en.i18n.json | 4 ++++ models/settings.js | 11 ++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/client/components/settings/settingBody.js b/client/components/settings/settingBody.js index e2d0383f9..5b0159186 100644 --- a/client/components/settings/settingBody.js +++ b/client/components/settings/settingBody.js @@ -128,11 +128,14 @@ BlazeComponent.extendComponent({ sendSMTPTestEmail() { Meteor.call('sendSMTPTestEmail', (err, ret) => { if (!err && ret) { /* eslint-disable no-console */ - console.log('Success:', ret.message, ret.email); - alert('Success'); + const message = `${TAPi18n.__(ret.message)}: ${ret.email}`; + console.log(message); + alert(message); } else { - console.log('Error: Sending test email', err); - alert(err); + const reason = err.reason || ''; + const message = `${TAPi18n.__(err.error)}\n${reason}`; + console.log(message, err); + alert(message); } /* eslint-enable no-console */ }); }, diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 11a9eef66..91a06ed2e 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -184,6 +184,7 @@ "email-enrollAccount-subject": "An account created for you on __siteName__", "email-enrollAccount-text": "Hello __user__,\n\nTo start using the service, simply click the link below.\n\n__url__\n\nThanks.", "email-fail": "Sending email failed", + "email-fail-text": "Error trying to send email", "email-invalid": "Invalid email", "email-invite": "Invite via Email", "email-invite-subject": "__inviter__ sent you an invitation", @@ -239,6 +240,7 @@ "initials": "Initials", "invalid-date": "Invalid date", "invalid-time": "Invalid time", + "invalid-user": "Invalid user", "joined": "joined", "just-invited": "You are just invited to this board", "keyboard-shortcuts": "Keyboard shortcuts", @@ -390,6 +392,8 @@ "invitation-code": "Invitation Code", "email-invite-register-subject": "__inviter__ sent you an invitation", "email-invite-register-text": "Dear __user__,\n\n__inviter__ invites you to Wekan for collaborations.\n\nPlease follow the link below:\n__url__\n\nAnd your invitation code is: __icode__\n\nThanks.", + "email-smtp-test-subject": "SMTP Test Email From Wekan", + "email-smtp-test-text": "You have successfully sent an email", "error-invitation-code-not-exist": "Invitation code doesn't exist", "error-notAuthorized": "You are not authorized to view this page.", "outgoing-webhooks": "Outgoing Webhooks", diff --git a/models/settings.js b/models/settings.js index a05f22725..34f693d9e 100644 --- a/models/settings.js +++ b/models/settings.js @@ -144,22 +144,23 @@ if (Meteor.isServer) { sendSMTPTestEmail() { if (!Meteor.userId()) { - throw new Meteor.Error('error-invalid-user', 'Invalid user'); + throw new Meteor.Error('invalid-user'); } const user = Meteor.user(); if (!user.emails && !user.emails[0] && user.emails[0].address) { - throw new Meteor.Error('error-invalid-email', 'Invalid email'); + throw new Meteor.Error('email-invalid'); } this.unblock(); + const lang = user.getLanguage(); try { Email.send({ to: user.emails[0].address, from: Accounts.emailTemplates.from, - subject: 'SMTP Test Email From Wekan', - text: 'You have successfully sent an email', + subject: TAPi18n.__('email-smtp-test-subject', {lng: lang}), + text: TAPi18n.__('email-smtp-test-text', {lng: lang}), }); } catch ({message}) { - throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${ message }`, message); + throw new Meteor.Error('email-fail', `${TAPi18n.__('email-fail-text', {lng: lang})}: ${ message }`, message); } return { message: 'email-sent',