From dffe3d5ade15582ec71714031509a314a2616667 Mon Sep 17 00:00:00 2001 From: nztqa Date: Mon, 27 Nov 2017 16:44:19 +0900 Subject: Add test SMTP settings --- models/settings.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'models/settings.js') diff --git a/models/settings.js b/models/settings.js index a02bb3fb..a05f2272 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, + }; + }, }); } -- cgit v1.2.3-1-g7c22 From 44559b52a6d45df57f1ca8eeaae25d55eb7e8148 Mon Sep 17 00:00:00 2001 From: nztqa Date: Tue, 28 Nov 2017 13:26:46 +0900 Subject: Add smtp test email translations --- models/settings.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'models/settings.js') diff --git a/models/settings.js b/models/settings.js index a05f2272..34f693d9 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', -- cgit v1.2.3-1-g7c22