[Update] 邮件设置添加配置项:发送账号 (#2795)

pull/2816/head
BaiJiangJie 2019-06-14 10:36:29 +08:00 committed by GitHub
parent 08a32028c1
commit 41a5a69164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 69 deletions

View File

@ -24,7 +24,8 @@ def send_mail_async(*args, **kwargs):
if len(args) == 3: if len(args) == 3:
args = list(args) args = list(args)
args[0] = settings.EMAIL_SUBJECT_PREFIX + args[0] args[0] = settings.EMAIL_SUBJECT_PREFIX + args[0]
args.insert(2, settings.EMAIL_HOST_USER) email_from = settings.EMAIL_FROM or settings.EMAIL_HOST_USER
args.insert(2, email_from)
args = tuple(args) args = tuple(args)
try: try:

View File

@ -353,6 +353,7 @@ EMAIL_HOST = 'smtp.jumpserver.org'
EMAIL_PORT = 25 EMAIL_PORT = 25
EMAIL_HOST_USER = 'noreply@jumpserver.org' EMAIL_HOST_USER = 'noreply@jumpserver.org'
EMAIL_HOST_PASSWORD = '' EMAIL_HOST_PASSWORD = ''
EMAIL_FROM = ''
EMAIL_USE_SSL = False EMAIL_USE_SSL = False
EMAIL_USE_TLS = False EMAIL_USE_TLS = False
EMAIL_SUBJECT_PREFIX = '[JMS] ' EMAIL_SUBJECT_PREFIX = '[JMS] '

Binary file not shown.

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Jumpserver 0.3.3\n" "Project-Id-Version: Jumpserver 0.3.3\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-06-12 17:56+0800\n" "POT-Creation-Date: 2019-06-14 10:30+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n" "Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: Jumpserver team<ibuler@qq.com>\n" "Language-Team: Jumpserver team<ibuler@qq.com>\n"
@ -742,7 +742,7 @@ msgstr "密码或密钥密码"
#: authentication/forms.py:13 #: authentication/forms.py:13
#: authentication/templates/authentication/login.html:67 #: authentication/templates/authentication/login.html:67
#: authentication/templates/authentication/new_login.html:93 #: authentication/templates/authentication/new_login.html:93
#: settings/forms.py:103 users/forms.py:15 users/forms.py:27 #: settings/forms.py:110 users/forms.py:15 users/forms.py:27
#: users/templates/users/reset_password.html:53 #: users/templates/users/reset_password.html:53
#: users/templates/users/user_password_authentication.html:18 #: users/templates/users/user_password_authentication.html:18
#: users/templates/users/user_password_update.html:43 #: users/templates/users/user_password_update.html:43
@ -809,7 +809,7 @@ msgstr "使用逗号分隔多个命令,如: /bin/whoami,/sbin/ifconfig"
#: assets/templates/assets/user_asset_list.html:45 #: assets/templates/assets/user_asset_list.html:45
#: assets/templates/assets/user_asset_list.html:167 #: assets/templates/assets/user_asset_list.html:167
#: audits/templates/audits/login_log_list.html:54 #: audits/templates/audits/login_log_list.html:54
#: perms/templates/perms/asset_permission_asset.html:55 settings/forms.py:133 #: perms/templates/perms/asset_permission_asset.html:55 settings/forms.py:140
#: users/templates/users/user_granted_asset.html:45 #: users/templates/users/user_granted_asset.html:45
#: users/templates/users/user_group_granted_asset.html:45 #: users/templates/users/user_group_granted_asset.html:45
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_asset_list.html:51 #: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_asset_list.html:51
@ -826,7 +826,7 @@ msgstr "IP"
#: assets/templates/assets/user_asset_list.html:44 #: assets/templates/assets/user_asset_list.html:44
#: assets/templates/assets/user_asset_list.html:166 #: assets/templates/assets/user_asset_list.html:166
#: perms/templates/perms/asset_permission_asset.html:54 #: perms/templates/perms/asset_permission_asset.html:54
#: perms/templates/perms/asset_permission_list.html:77 settings/forms.py:132 #: perms/templates/perms/asset_permission_list.html:77 settings/forms.py:139
#: users/templates/users/user_granted_asset.html:44 #: users/templates/users/user_granted_asset.html:44
#: users/templates/users/user_group_granted_asset.html:44 #: users/templates/users/user_group_granted_asset.html:44
#: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_asset_list.html:50 #: xpack/plugins/change_auth_plan/templates/change_auth_plan/plan_asset_list.html:50
@ -2633,7 +2633,7 @@ msgstr "等待任务开始"
msgid "Interval" msgid "Interval"
msgstr "间隔" msgstr "间隔"
#: ops/models/adhoc.py:38 settings/forms.py:151 #: ops/models/adhoc.py:38 settings/forms.py:158
msgid "Units: seconds" msgid "Units: seconds"
msgstr "单位: 秒" msgstr "单位: 秒"
@ -2970,7 +2970,7 @@ msgstr "命令执行"
msgid "Organization" msgid "Organization"
msgstr "组织管理" msgstr "组织管理"
#: perms/const.py:18 settings/forms.py:136 #: perms/const.py:18 settings/forms.py:143
msgid "All" msgid "All"
msgstr "全部" msgstr "全部"
@ -3229,29 +3229,29 @@ msgstr "远程应用授权远程应用列表"
msgid "Test mail sent to {}, please check" msgid "Test mail sent to {}, please check"
msgstr "邮件已经发送{}, 请检查" msgstr "邮件已经发送{}, 请检查"
#: settings/api.py:52 #: settings/api.py:54
msgid "Test ldap success" msgid "Test ldap success"
msgstr "连接LDAP成功" msgstr "连接LDAP成功"
#: settings/api.py:89 #: settings/api.py:91
msgid "Match {} s users" msgid "Match {} s users"
msgstr "匹配 {} 个用户" msgstr "匹配 {} 个用户"
#: settings/api.py:158 #: settings/api.py:160
msgid "succeed: {} failed: {} total: {}" msgid "succeed: {} failed: {} total: {}"
msgstr "成功:{} 失败:{} 总数:{}" msgstr "成功:{} 失败:{} 总数:{}"
#: settings/api.py:180 settings/api.py:216 #: settings/api.py:182 settings/api.py:218
msgid "" msgid ""
"Error: Account invalid (Please make sure the information such as Access key " "Error: Account invalid (Please make sure the information such as Access key "
"or Secret key is correct)" "or Secret key is correct)"
msgstr "错误:账户无效 (请确保 Access key 或 Secret key 等信息正确)" msgstr "错误:账户无效 (请确保 Access key 或 Secret key 等信息正确)"
#: settings/api.py:186 settings/api.py:222 #: settings/api.py:188 settings/api.py:224
msgid "Create succeed" msgid "Create succeed"
msgstr "创建成功" msgstr "创建成功"
#: settings/api.py:204 settings/api.py:242 #: settings/api.py:206 settings/api.py:244
#: settings/templates/settings/terminal_setting.html:154 #: settings/templates/settings/terminal_setting.html:154
msgid "Delete succeed" msgid "Delete succeed"
msgstr "删除成功" msgstr "删除成功"
@ -3292,56 +3292,64 @@ msgstr "SMTP账号"
msgid "SMTP password" msgid "SMTP password"
msgstr "SMTP密码" msgstr "SMTP密码"
#: settings/forms.py:83 #: settings/forms.py:84
msgid "Some provider use token except password" msgid "Tips: Some provider use token except password"
msgstr "一些邮件提供商需要输入的是Token" msgstr "提示:一些邮件提供商需要输入的是Token"
#: settings/forms.py:86 #: settings/forms.py:87
msgid "Send user"
msgstr "发送账号"
#: settings/forms.py:89
msgid "Tips: Send mail account, default SMTP account as the send account"
msgstr "提示:发送邮件账号,默认使用 SMTP账号 作为发送账号"
#: settings/forms.py:93
msgid "Use SSL" msgid "Use SSL"
msgstr "使用SSL" msgstr "使用SSL"
#: settings/forms.py:87 #: settings/forms.py:94
msgid "If SMTP port is 465, may be select" msgid "If SMTP port is 465, may be select"
msgstr "如果SMTP端口是465通常需要启用SSL" msgstr "如果SMTP端口是465通常需要启用SSL"
#: settings/forms.py:90 #: settings/forms.py:97
msgid "Use TLS" msgid "Use TLS"
msgstr "使用TLS" msgstr "使用TLS"
#: settings/forms.py:91 #: settings/forms.py:98
msgid "If SMTP port is 587, may be select" msgid "If SMTP port is 587, may be select"
msgstr "如果SMTP端口是587通常需要启用TLS" msgstr "如果SMTP端口是587通常需要启用TLS"
#: settings/forms.py:97 #: settings/forms.py:104
msgid "LDAP server" msgid "LDAP server"
msgstr "LDAP地址" msgstr "LDAP地址"
#: settings/forms.py:100 #: settings/forms.py:107
msgid "Bind DN" msgid "Bind DN"
msgstr "绑定DN" msgstr "绑定DN"
#: settings/forms.py:107 #: settings/forms.py:114
msgid "User OU" msgid "User OU"
msgstr "用户OU" msgstr "用户OU"
#: settings/forms.py:108 #: settings/forms.py:115
msgid "Use | split User OUs" msgid "Use | split User OUs"
msgstr "使用|分隔各OU" msgstr "使用|分隔各OU"
#: settings/forms.py:112 #: settings/forms.py:119
msgid "User search filter" msgid "User search filter"
msgstr "用户过滤器" msgstr "用户过滤器"
#: settings/forms.py:113 #: settings/forms.py:120
#, python-format #, python-format
msgid "Choice may be (cn|uid|sAMAccountName)=%(user)s)" msgid "Choice may be (cn|uid|sAMAccountName)=%(user)s)"
msgstr "可能的选项是(cn或uid或sAMAccountName=%(user)s)" msgstr "可能的选项是(cn或uid或sAMAccountName=%(user)s)"
#: settings/forms.py:116 #: settings/forms.py:123
msgid "User attr map" msgid "User attr map"
msgstr "LDAP属性映射" msgstr "LDAP属性映射"
#: settings/forms.py:118 #: settings/forms.py:125
msgid "" msgid ""
"User attr map present how to map LDAP user attr to jumpserver, username,name," "User attr map present how to map LDAP user attr to jumpserver, username,name,"
"email is jumpserver attr" "email is jumpserver attr"
@ -3349,39 +3357,39 @@ msgstr ""
"用户属性映射代表怎样将LDAP中用户属性映射到jumpserver用户上username, name," "用户属性映射代表怎样将LDAP中用户属性映射到jumpserver用户上username, name,"
"email 是jumpserver的属性" "email 是jumpserver的属性"
#: settings/forms.py:127 #: settings/forms.py:134
msgid "Enable LDAP auth" msgid "Enable LDAP auth"
msgstr "启用LDAP认证" msgstr "启用LDAP认证"
#: settings/forms.py:137 #: settings/forms.py:144
msgid "Auto" msgid "Auto"
msgstr "自动" msgstr "自动"
#: settings/forms.py:144 #: settings/forms.py:151
msgid "Password auth" msgid "Password auth"
msgstr "密码认证" msgstr "密码认证"
#: settings/forms.py:147 #: settings/forms.py:154
msgid "Public key auth" msgid "Public key auth"
msgstr "密钥认证" msgstr "密钥认证"
#: settings/forms.py:150 #: settings/forms.py:157
msgid "Heartbeat interval" msgid "Heartbeat interval"
msgstr "心跳间隔" msgstr "心跳间隔"
#: settings/forms.py:154 #: settings/forms.py:161
msgid "List sort by" msgid "List sort by"
msgstr "资产列表排序" msgstr "资产列表排序"
#: settings/forms.py:157 #: settings/forms.py:164
msgid "List page size" msgid "List page size"
msgstr "资产分页每页数量" msgstr "资产分页每页数量"
#: settings/forms.py:160 #: settings/forms.py:167
msgid "Session keep duration" msgid "Session keep duration"
msgstr "会话保留时长" msgstr "会话保留时长"
#: settings/forms.py:161 #: settings/forms.py:168
msgid "" msgid ""
"Units: days, Session, record, command will be delete if more than duration, " "Units: days, Session, record, command will be delete if more than duration, "
"only in database" "only in database"
@ -3389,62 +3397,62 @@ msgstr ""
"单位:天。 会话、录像、命令记录超过该时长将会被删除(仅影响数据库存储, oss等不" "单位:天。 会话、录像、命令记录超过该时长将会被删除(仅影响数据库存储, oss等不"
"受影响)" "受影响)"
#: settings/forms.py:165 #: settings/forms.py:172
msgid "Telnet login regex" msgid "Telnet login regex"
msgstr "Telnet 成功正则表达式" msgstr "Telnet 成功正则表达式"
#: settings/forms.py:166 #: settings/forms.py:173
msgid "ex: Last\\s*login|success|成功" msgid "ex: Last\\s*login|success|成功"
msgstr "" msgstr ""
"登录telnet服务器成功后的提示正则表达式如: Last\\s*login|success|成功 " "登录telnet服务器成功后的提示正则表达式如: Last\\s*login|success|成功 "
#: settings/forms.py:177 #: settings/forms.py:184
msgid "MFA Secondary certification" msgid "MFA Secondary certification"
msgstr "MFA 二次认证" msgstr "MFA 二次认证"
#: settings/forms.py:179 #: settings/forms.py:186
msgid "" msgid ""
"After opening, the user login must use MFA secondary authentication (valid " "After opening, the user login must use MFA secondary authentication (valid "
"for all users, including administrators)" "for all users, including administrators)"
msgstr "开启后用户登录必须使用MFA二次认证对所有用户有效包括管理员" msgstr "开启后用户登录必须使用MFA二次认证对所有用户有效包括管理员"
#: settings/forms.py:185 #: settings/forms.py:192
msgid "Batch execute commands" msgid "Batch execute commands"
msgstr "批量命令" msgstr "批量命令"
#: settings/forms.py:186 #: settings/forms.py:193
msgid "Allow user batch execute commands" msgid "Allow user batch execute commands"
msgstr "允许用户批量执行命令" msgstr "允许用户批量执行命令"
#: settings/forms.py:191 #: settings/forms.py:198
msgid "Limit the number of login failures" msgid "Limit the number of login failures"
msgstr "限制登录失败次数" msgstr "限制登录失败次数"
#: settings/forms.py:195 #: settings/forms.py:202
msgid "No logon interval" msgid "No logon interval"
msgstr "禁止登录时间间隔" msgstr "禁止登录时间间隔"
#: settings/forms.py:197 #: settings/forms.py:204
msgid "" msgid ""
"Tip: (unit/minute) if the user has failed to log in for a limited number of " "Tip: (unit/minute) if the user has failed to log in for a limited number of "
"times, no login is allowed during this time interval." "times, no login is allowed during this time interval."
msgstr "" msgstr ""
"提示:(单位:分)当用户登录失败次数达到限制后,那么在此时间间隔内禁止登录" "提示:(单位:分)当用户登录失败次数达到限制后,那么在此时间间隔内禁止登录"
#: settings/forms.py:204 #: settings/forms.py:211
msgid "Connection max idle time" msgid "Connection max idle time"
msgstr "SSH最大空闲时间" msgstr "SSH最大空闲时间"
#: settings/forms.py:206 #: settings/forms.py:213
msgid "" msgid ""
"If idle time more than it, disconnect connection(only ssh now) Unit: minute" "If idle time more than it, disconnect connection(only ssh now) Unit: minute"
msgstr "提示单位如果超过该配置没有操作连接会被断开仅ssh" msgstr "提示单位如果超过该配置没有操作连接会被断开仅ssh"
#: settings/forms.py:212 #: settings/forms.py:219
msgid "Password expiration time" msgid "Password expiration time"
msgstr "密码过期时间" msgstr "密码过期时间"
#: settings/forms.py:214 #: settings/forms.py:221
msgid "" msgid ""
"Tip: (unit: day) If the user does not update the password during the time, " "Tip: (unit: day) If the user does not update the password during the time, "
"the user password will expire failure;The password expiration reminder mail " "the user password will expire failure;The password expiration reminder mail "
@ -3454,81 +3462,81 @@ msgstr ""
"提示:(单位:天)如果用户在此期间没有更新密码,用户密码将过期失效; 密码过期" "提示:(单位:天)如果用户在此期间没有更新密码,用户密码将过期失效; 密码过期"
"提醒邮件将在密码过期前5天内由系统每天自动发送给用户" "提醒邮件将在密码过期前5天内由系统每天自动发送给用户"
#: settings/forms.py:223 #: settings/forms.py:230
msgid "Password minimum length" msgid "Password minimum length"
msgstr "密码最小长度 " msgstr "密码最小长度 "
#: settings/forms.py:227 #: settings/forms.py:234
msgid "Must contain capital letters" msgid "Must contain capital letters"
msgstr "必须包含大写字母" msgstr "必须包含大写字母"
#: settings/forms.py:229 #: settings/forms.py:236
msgid "" msgid ""
"After opening, the user password changes and resets must contain uppercase " "After opening, the user password changes and resets must contain uppercase "
"letters" "letters"
msgstr "开启后,用户密码修改、重置必须包含大写字母" msgstr "开启后,用户密码修改、重置必须包含大写字母"
#: settings/forms.py:234 #: settings/forms.py:241
msgid "Must contain lowercase letters" msgid "Must contain lowercase letters"
msgstr "必须包含小写字母" msgstr "必须包含小写字母"
#: settings/forms.py:235 #: settings/forms.py:242
msgid "" msgid ""
"After opening, the user password changes and resets must contain lowercase " "After opening, the user password changes and resets must contain lowercase "
"letters" "letters"
msgstr "开启后,用户密码修改、重置必须包含小写字母" msgstr "开启后,用户密码修改、重置必须包含小写字母"
#: settings/forms.py:240 #: settings/forms.py:247
msgid "Must contain numeric characters" msgid "Must contain numeric characters"
msgstr "必须包含数字字符" msgstr "必须包含数字字符"
#: settings/forms.py:241 #: settings/forms.py:248
msgid "" msgid ""
"After opening, the user password changes and resets must contain numeric " "After opening, the user password changes and resets must contain numeric "
"characters" "characters"
msgstr "开启后,用户密码修改、重置必须包含数字字符" msgstr "开启后,用户密码修改、重置必须包含数字字符"
#: settings/forms.py:246 #: settings/forms.py:253
msgid "Must contain special characters" msgid "Must contain special characters"
msgstr "必须包含特殊字符" msgstr "必须包含特殊字符"
#: settings/forms.py:247 #: settings/forms.py:254
msgid "" msgid ""
"After opening, the user password changes and resets must contain special " "After opening, the user password changes and resets must contain special "
"characters" "characters"
msgstr "开启后,用户密码修改、重置必须包含特殊字符" msgstr "开启后,用户密码修改、重置必须包含特殊字符"
#: settings/forms.py:254 #: settings/forms.py:261
msgid "Create user email subject" msgid "Create user email subject"
msgstr "创建用户邮件的主题" msgstr "创建用户邮件的主题"
#: settings/forms.py:255 #: settings/forms.py:262
msgid "" msgid ""
"Tips: When creating a user, send the subject of the email (eg:Create account " "Tips: When creating a user, send the subject of the email (eg:Create account "
"successfully)" "successfully)"
msgstr "提示: 创建用户时,发送设置密码邮件的主题 (例如: 创建用户成功)" msgstr "提示: 创建用户时,发送设置密码邮件的主题 (例如: 创建用户成功)"
#: settings/forms.py:259 #: settings/forms.py:266
msgid "Create user honorific" msgid "Create user honorific"
msgstr "创建用户邮件的敬语" msgstr "创建用户邮件的敬语"
#: settings/forms.py:260 #: settings/forms.py:267
msgid "Tips: When creating a user, send the honorific of the email (eg:Hello)" msgid "Tips: When creating a user, send the honorific of the email (eg:Hello)"
msgstr "提示: 创建用户时,发送设置密码邮件的敬语 (例如: 您好)" msgstr "提示: 创建用户时,发送设置密码邮件的敬语 (例如: 您好)"
#: settings/forms.py:265 #: settings/forms.py:272
msgid "Create user email content" msgid "Create user email content"
msgstr "创建用户邮件的内容" msgstr "创建用户邮件的内容"
#: settings/forms.py:266 #: settings/forms.py:273
msgid "Tips:When creating a user, send the content of the email" msgid "Tips:When creating a user, send the content of the email"
msgstr "提示: 创建用户时,发送设置密码邮件的内容" msgstr "提示: 创建用户时,发送设置密码邮件的内容"
#: settings/forms.py:269 #: settings/forms.py:276
msgid "Signature" msgid "Signature"
msgstr "署名" msgstr "署名"
#: settings/forms.py:270 #: settings/forms.py:277
msgid "Tips: Email signature (eg:jumpserver)" msgid "Tips: Email signature (eg:jumpserver)"
msgstr "提示: 邮件的署名 (例如: jumpserver)" msgstr "提示: 邮件的署名 (例如: jumpserver)"

View File

@ -30,6 +30,7 @@ class MailTestingAPI(APIView):
def post(self, request): def post(self, request):
serializer = self.serializer_class(data=request.data) serializer = self.serializer_class(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
email_from = serializer.validated_data["EMAIL_FROM"]
email_host_user = serializer.validated_data["EMAIL_HOST_USER"] email_host_user = serializer.validated_data["EMAIL_HOST_USER"]
for k, v in serializer.validated_data.items(): for k, v in serializer.validated_data.items():
if k.startswith('EMAIL'): if k.startswith('EMAIL'):
@ -37,7 +38,8 @@ class MailTestingAPI(APIView):
try: try:
subject = "Test" subject = "Test"
message = "Test smtp setting" message = "Test smtp setting"
send_mail(subject, message, email_host_user, [email_host_user]) email_from = email_from or email_host_user
send_mail(subject, message, email_from, [email_host_user])
except Exception as e: except Exception as e:
return Response({"error": str(e)}, status=401) return Response({"error": str(e)}, status=401)

View File

@ -80,7 +80,14 @@ class EmailSettingForm(BaseForm):
) )
EMAIL_HOST_PASSWORD = FormEncryptCharField( EMAIL_HOST_PASSWORD = FormEncryptCharField(
max_length=1024, label=_("SMTP password"), widget=forms.PasswordInput, max_length=1024, label=_("SMTP password"), widget=forms.PasswordInput,
required=False, help_text=_("Some provider use token except password") required=False,
help_text=_("Tips: Some provider use token except password")
)
EMAIL_FROM = forms.CharField(
max_length=128, label=_("Send user"), initial='', required=False,
help_text=_(
"Tips: Send mail account, default SMTP account as the send account"
)
) )
EMAIL_USE_SSL = forms.BooleanField( EMAIL_USE_SSL = forms.BooleanField(
label=_("Use SSL"), initial=False, required=False, label=_("Use SSL"), initial=False, required=False,

View File

@ -6,6 +6,7 @@ class MailTestSerializer(serializers.Serializer):
EMAIL_PORT = serializers.IntegerField(default=25) EMAIL_PORT = serializers.IntegerField(default=25)
EMAIL_HOST_USER = serializers.CharField(max_length=1024) EMAIL_HOST_USER = serializers.CharField(max_length=1024)
EMAIL_HOST_PASSWORD = serializers.CharField() EMAIL_HOST_PASSWORD = serializers.CharField()
EMAIL_FROM = serializers.CharField(required=False, allow_blank=True)
EMAIL_USE_SSL = serializers.BooleanField(default=False) EMAIL_USE_SSL = serializers.BooleanField(default=False)
EMAIL_USE_TLS = serializers.BooleanField(default=False) EMAIL_USE_TLS = serializers.BooleanField(default=False)