Sotaro KARASAWA 11 лет назад
Родитель
Сommit
a840b154e3
3 измененных файлов с 18 добавлено и 12 удалено
  1. 15 10
      lib/mailer.js
  2. 1 1
      routes/admin.js
  3. 2 1
      views/admin/app.html

+ 15 - 10
lib/mailer.js

@@ -13,11 +13,11 @@ module.exports = function(app) {
     ;
 
 
-  function createSmtpClient(option)
+  function createSMTPClient(option)
   {
     var client;
 
-    debug('createSmtpClient option', option);
+    debug('createSMTPClient option', option);
     if (!option) {
       option = {
         host: config.crowi['mail:smtpHost'],
@@ -33,6 +33,8 @@ module.exports = function(app) {
     }
 
     client = nodemailer.createTransport(option);
+
+    debug('mailer setted up for SMTP', client);
     return client;
   }
 
@@ -50,11 +52,12 @@ module.exports = function(app) {
     var ses = require('nodemailer-ses-transport');
     var client = nodemailer.createTransport(ses(option));
 
+    debug('mailer setted up for SES', client);
     return client;
   }
 
   function initialize() {
-    if (!config.crowi['mail.from']) {
+    if (!config.crowi['mail:from']) {
       mailer = undefined;
       return;
     }
@@ -65,17 +68,20 @@ module.exports = function(app) {
         && config.crowi['mail:smtpPort']
       ) {
       // SMTP 設定がある場合はそれを優先
-      mailer = createSmtpClient();
+      mailer = createSMTPClient();
 
-    } else if (config.crowi['aws:accessKeyId'] && config.crowi['aws:secretAccessKey']) {
+    } else if (config.crowi['aws:accessKeyId']
+      && config.crowi['aws:secretAccessKey']) {
       // AWS 設定がある場合はSESを設定
       mailer = createSESClient();
     } else {
       mailer = undefined;
     }
 
-    mailConfig.from = config.crowi['mail.from'];
+    mailConfig.from = config.crowi['mail:from'];
     mailConfig.subject = config.crowi['app:title'] + 'からのメール';
+
+    debug('mailer initialized');
   }
 
   function setupMailConfig (overrideConfig) {
@@ -87,7 +93,6 @@ module.exports = function(app) {
     mc.to      = c.to;
     mc.to      = 'Sotaro <sotarok@crocos.co.jp>'; // for test
     mc.from    = c.from || mailConfig.from;
-    mc.from    = 'Crowi <reg@sotaro-k.com>'; // for test
     mc.text    = c.text;
     mc.subject = c.subject || mailConfig.subject;
 
@@ -96,10 +101,10 @@ module.exports = function(app) {
 
   function send(config, callback) {
     if (mailer) {
-      mailer.sendMail(setupMailConfig(config));
+      return mailer.sendMail(setupMailConfig(config), callback);
     } else {
       debug('Mailer is not completed to set up. Please set up SMTP or AWS setting.');
-      callback(new Error('Mailer is not completed to set up. Please set up SMTP or AWS setting.'), null);
+      return callback(new Error('Mailer is not completed to set up. Please set up SMTP or AWS setting.'), null);
     }
   }
 
@@ -107,7 +112,7 @@ module.exports = function(app) {
   initialize();
 
   return {
-    createSmtpClient: createSmtpClient,
+    createSMTPClient: createSMTPClient,
     createSESClient: createSESClient,
     mailer: mailer,
     send: send,

+ 1 - 1
routes/admin.js

@@ -203,7 +203,7 @@ module.exports = function(app) {
       option.secure = true;
     }
 
-    var smtpClient = mailer.createSmtpClient(option);
+    var smtpClient = mailer.createSMTPClient(option);
     debug('mailer setup for validate SMTP setting', smtpClient);
 
     smtpClient.sendMail({

+ 2 - 1
views/admin/app.html

@@ -162,7 +162,8 @@
       <form action="/_api/admin/settings/aws" method="post" class="form-horizontal" id="awsSettingForm" role="form">
       <fieldset>
       <legend>AWS設定</legend>
-        <p class="well">S3 にアクセスするための設定を行います。AWS の設定を完了させると、ファイルアップロード機能、プロフィール写真機能などが有効になります。<br>
+        <p class="well">AWS にアクセスするための設定を行います。AWS の設定を完了させると、ファイルアップロード機能、プロフィール写真機能などが有効になります。<br>
+        また、SMTP の設定が無い場合、SES を利用したメール送信が行われます。FromメールアドレスのVerify、プロダクション利用設定をする必要があります。<br>
           <br>
 
           <span class="text-danger"><i class="fa fa-warning"></i> この設定を途中で変更すると、これまでにアップロードしたファイル等へのアクセスができなくなりますのでご注意下さい。</span>