|
@@ -318,7 +318,7 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
/**
|
|
|
* validate mail setting send test mail
|
|
* validate mail setting send test mail
|
|
|
*/
|
|
*/
|
|
|
- async function sendTestEmail(req) {
|
|
|
|
|
|
|
+ async function sendTestEmail(destinationAddress) {
|
|
|
|
|
|
|
|
const { configManager, mailService } = crowi;
|
|
const { configManager, mailService } = crowi;
|
|
|
|
|
|
|
@@ -331,14 +331,19 @@ module.exports = (crowi) => {
|
|
|
throw Error('fromAddress is not setup');
|
|
throw Error('fromAddress is not setup');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const smtpHost = configManager.getConfig('crowi', 'mail:smtpHost');
|
|
|
|
|
+ const smtpPort = configManager.getConfig('crowi', 'mail:smtpPort');
|
|
|
|
|
+ const smtpUser = configManager.getConfig('crowi', 'mail:smtpUser');
|
|
|
|
|
+ const smtpPassword = configManager.getConfig('crowi', 'mail:smtpPassword');
|
|
|
|
|
+
|
|
|
const option = {
|
|
const option = {
|
|
|
- host: req.body.smtpHost,
|
|
|
|
|
- port: req.body.smtpPort,
|
|
|
|
|
|
|
+ host: smtpHost,
|
|
|
|
|
+ port: smtpPort,
|
|
|
};
|
|
};
|
|
|
- if (req.body.smtpUser && req.body.smtpPassword) {
|
|
|
|
|
|
|
+ if (smtpUser && smtpPassword) {
|
|
|
option.auth = {
|
|
option.auth = {
|
|
|
- user: req.body.smtpUser,
|
|
|
|
|
- pass: req.body.smtpPassword,
|
|
|
|
|
|
|
+ user: smtpUser,
|
|
|
|
|
+ pass: smtpPassword,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
if (option.port === 465) {
|
|
if (option.port === 465) {
|
|
@@ -350,7 +355,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
const mailOptions = {
|
|
|
from: fromAddress,
|
|
from: fromAddress,
|
|
|
- to: req.user.email,
|
|
|
|
|
|
|
+ to: destinationAddress,
|
|
|
subject: 'Wiki管理設定のアップデートによるメール通知',
|
|
subject: 'Wiki管理設定のアップデートによるメール通知',
|
|
|
text: 'このメールは、WikiのSMTP設定のアップデートにより送信されています。',
|
|
text: 'このメールは、WikiのSMTP設定のアップデートにより送信されています。',
|
|
|
};
|
|
};
|
|
@@ -372,10 +377,13 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
isMailerSetup: mailService.isMailerSetup,
|
|
isMailerSetup: mailService.isMailerSetup,
|
|
|
|
|
+ fromAddress: configManager.getConfig('crowi', 'mail:from'),
|
|
|
smtpHost: configManager.getConfig('crowi', 'mail:smtpHost'),
|
|
smtpHost: configManager.getConfig('crowi', 'mail:smtpHost'),
|
|
|
smtpPort: configManager.getConfig('crowi', 'mail:smtpPort'),
|
|
smtpPort: configManager.getConfig('crowi', 'mail:smtpPort'),
|
|
|
smtpUser: configManager.getConfig('crowi', 'mail:smtpUser'),
|
|
smtpUser: configManager.getConfig('crowi', 'mail:smtpUser'),
|
|
|
smtpPassword: configManager.getConfig('crowi', 'mail:smtpPassword'),
|
|
smtpPassword: configManager.getConfig('crowi', 'mail:smtpPassword'),
|
|
|
|
|
+ sesAccessKeyId: configManager.getConfig('crowi', 'mail:sesAccessKeyId'),
|
|
|
|
|
+ sesSecretAccessKey: configManager.getConfig('crowi', 'mail:sesSecretAccessKey'),
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -429,29 +437,23 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/smtp-test:
|
|
* /app-settings/smtp-test:
|
|
|
* post:
|
|
* post:
|
|
|
* tags: [AppSettings]
|
|
* tags: [AppSettings]
|
|
|
- * operationId: posyAppSettingSmtpTast
|
|
|
|
|
|
|
+ * operationId: postSmtpTest
|
|
|
* summary: /app-settings/smtp-setting
|
|
* summary: /app-settings/smtp-setting
|
|
|
* description: Send test mail for smtp
|
|
* description: Send test mail for smtp
|
|
|
- * requestBody:
|
|
|
|
|
- * required: true
|
|
|
|
|
- * content:
|
|
|
|
|
- * application/json:
|
|
|
|
|
- * schema:
|
|
|
|
|
- * $ref: '#/components/schemas/SmtpSettingParams'
|
|
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
* description: Succeeded to send test mail for smtp
|
|
* description: Succeeded to send test mail for smtp
|
|
|
*/
|
|
*/
|
|
|
- router.post('/smtp-test', loginRequiredStrictly, adminRequired, csrf, validator.smtpSetting, apiV3FormValidator, async(req, res) => {
|
|
|
|
|
|
|
+ router.post('/smtp-test', loginRequiredStrictly, adminRequired, async(req, res) => {
|
|
|
try {
|
|
try {
|
|
|
- await sendTestEmail(req);
|
|
|
|
|
|
|
+ await sendTestEmail(req.user.email);
|
|
|
return res.apiv3({});
|
|
return res.apiv3({});
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
const msg = req.t('validation.failed_to_send_a_test_email');
|
|
const msg = req.t('validation.failed_to_send_a_test_email');
|
|
|
logger.error('Error', err);
|
|
logger.error('Error', err);
|
|
|
debug('Error validate mail setting: ', err);
|
|
debug('Error validate mail setting: ', err);
|
|
|
- return res.apiv3Err(new ErrorV3(msg, 'update-mailSetting-failed'));
|
|
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'send-email-with-smtp-failed'));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|