ソースを参照

Add test SMTP settings

nztqa 7 年 前
コミット
dffe3d5ade

+ 3 - 0
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

+ 11 - 0
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');

+ 1 - 0
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.",

+ 25 - 0
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,
+      };
+    },
   });
 }