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