// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import ErrorStore from 'stores/error_store.jsx';
import {ErrorBarTypes} from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
import AdminSettings from './admin_settings.jsx';
import BooleanSetting from './boolean_setting.jsx';
import {ConnectionSecurityDropdownSettingEmail} from './connection_security_dropdown_setting.jsx';
import DropdownSetting from './dropdown_setting.jsx';
import EmailConnectionTest from './email_connection_test.jsx';
import {FormattedHTMLMessage, FormattedMessage} from 'react-intl';
import SettingsGroup from './settings_group.jsx';
import TextSetting from './text_setting.jsx';
const EMAIL_NOTIFICATION_CONTENTS_FULL = 'full';
const EMAIL_NOTIFICATION_CONTENTS_GENERIC = 'generic';
export default class EmailSettings extends AdminSettings {
constructor(props) {
super(props);
this.getConfigFromState = this.getConfigFromState.bind(this);
this.handleSaved = this.handleSaved.bind(this);
this.renderSettings = this.renderSettings.bind(this);
}
getConfigFromState(config) {
config.EmailSettings.SendEmailNotifications = this.state.sendEmailNotifications;
config.EmailSettings.FeedbackName = this.state.feedbackName;
config.EmailSettings.FeedbackEmail = this.state.feedbackEmail;
config.EmailSettings.FeedbackOrganization = this.state.feedbackOrganization;
config.EmailSettings.EnableSMTPAuth = this.state.enableSMTPAuth;
config.EmailSettings.SMTPUsername = this.state.smtpUsername;
config.EmailSettings.SMTPPassword = this.state.smtpPassword;
config.EmailSettings.SMTPServer = this.state.smtpServer;
config.EmailSettings.SMTPPort = this.state.smtpPort;
config.EmailSettings.ConnectionSecurity = this.state.connectionSecurity;
config.EmailSettings.EnableEmailBatching = this.state.enableEmailBatching;
config.ServiceSettings.EnableSecurityFixAlert = this.state.enableSecurityFixAlert;
config.EmailSettings.SkipServerCertificateVerification = this.state.skipServerCertificateVerification;
config.EmailSettings.EmailNotificationContentsType = this.state.emailNotificationContentsType;
return config;
}
handleSaved(newConfig) {
if (newConfig.EmailSettings.SendEmailNotifications) {
ErrorStore.clearError(ErrorBarTypes.PREVIEW_MODE);
}
}
getStateFromConfig(config) {
return {
sendEmailNotifications: config.EmailSettings.SendEmailNotifications,
feedbackName: config.EmailSettings.FeedbackName,
feedbackEmail: config.EmailSettings.FeedbackEmail,
feedbackOrganization: config.EmailSettings.FeedbackOrganization,
enableSMTPAuth: config.EmailSettings.EnableSMTPAuth,
smtpUsername: config.EmailSettings.SMTPUsername,
smtpPassword: config.EmailSettings.SMTPPassword,
smtpServer: config.EmailSettings.SMTPServer,
smtpPort: config.EmailSettings.SMTPPort,
connectionSecurity: config.EmailSettings.ConnectionSecurity,
enableEmailBatching: config.EmailSettings.EnableEmailBatching,
skipServerCertificateVerification: config.EmailSettings.SkipServerCertificateVerification,
enableSecurityFixAlert: config.ServiceSettings.EnableSecurityFixAlert,
emailNotificationContentsType: config.EmailSettings.EmailNotificationContentsType
};
}
renderTitle() {
return (
);
}
renderSettings() {
let enableEmailBatchingDisabledText = null;
if (this.props.config.ClusterSettings.Enable) {
enableEmailBatchingDisabledText = (
);
} else if (!this.props.config.ServiceSettings.SiteURL) {
enableEmailBatchingDisabledText = (
);
}
let emailNotificationContentsTypeDropdown = null;
let emailNotificationContentsHelpText = null;
if (window.mm_license.EmailNotificationContents === 'true') {
const emailNotificationContentsTypes = [];
emailNotificationContentsTypes.push({value: EMAIL_NOTIFICATION_CONTENTS_FULL, text: Utils.localizeMessage('admin.email.notification.contents.full', 'Send full message contents')});
emailNotificationContentsTypes.push({value: EMAIL_NOTIFICATION_CONTENTS_GENERIC, text: Utils.localizeMessage('admin.email.notification.contents.generic', 'Send generic description with only sender name')});
if (this.state.emailNotificationContentsType === EMAIL_NOTIFICATION_CONTENTS_FULL) {
emailNotificationContentsHelpText = (
);
} else if (this.state.emailNotificationContentsType === EMAIL_NOTIFICATION_CONTENTS_GENERIC) {
emailNotificationContentsHelpText = (
);
}
emailNotificationContentsTypeDropdown = (
}
value={this.state.emailNotificationContentsType}
onChange={this.handleChange}
helpText={emailNotificationContentsHelpText}
/>
);
}
return (
}
helpText={
}
value={this.state.sendEmailNotifications}
onChange={this.handleChange}
/>
}
helpText={[
,
enableEmailBatchingDisabledText
]}
value={this.state.enableEmailBatching && !this.props.config.ClusterSettings.Enable && Boolean(this.props.config.ServiceSettings.SiteURL)}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications || this.props.config.ClusterSettings.Enable || !this.props.config.ServiceSettings.SiteURL}
/>
{emailNotificationContentsTypeDropdown}
}
placeholder={Utils.localizeMessage('admin.email.notificationDisplayExample', 'Ex: "Mattermost Notification", "System", "No-Reply"')}
helpText={
}
value={this.state.feedbackName}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications}
/>
}
placeholder={Utils.localizeMessage('admin.email.notificationEmailExample', 'Ex: "mattermost@yourcompany.com", "admin@yourcompany.com"')}
helpText={
}
value={this.state.feedbackEmail}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications}
/>
}
placeholder={Utils.localizeMessage('admin.email.notificationOrganizationExample', 'Ex: "© ABC Corporation, 565 Knight Way, Palo Alto, California, 94305, USA"')}
helpText={
}
value={this.state.feedbackOrganization}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications}
/>
}
placeholder={Utils.localizeMessage('admin.email.smtpServerExample', 'Ex: "smtp.yourcompany.com", "email-smtp.us-east-1.amazonaws.com"')}
helpText={
}
value={this.state.smtpServer}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications}
/>
}
placeholder={Utils.localizeMessage('admin.email.smtpPortExample', 'Ex: "25", "465", "587"')}
helpText={
}
value={this.state.smtpPort}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications}
/>
}
helpText={[
]}
value={this.state.enableSMTPAuth}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications}
/>
}
placeholder={Utils.localizeMessage('admin.email.smtpUsernameExample', 'Ex: "admin@yourcompany.com", "AKIADTOVBGERKLCBV"')}
helpText={
}
value={this.state.smtpUsername}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications || !this.state.enableSMTPAuth}
/>
}
placeholder={Utils.localizeMessage('admin.email.smtpPasswordExample', 'Ex: "yourpassword", "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
helpText={
}
value={this.state.smtpPassword}
onChange={this.handleChange}
disabled={!this.state.sendEmailNotifications || !this.state.enableSMTPAuth}
/>
}
helpText={
}
value={this.state.skipServerCertificateVerification}
onChange={this.handleChange}
/>
}
helpText={
}
value={this.state.enableSecurityFixAlert}
onChange={this.handleChange}
/>
);
}
}