perf: 新增邮件发送测试

This commit is contained in:
kuaifan 2022-04-07 14:22:59 +08:00
parent 2918c55fa9
commit 9755c59687
11 changed files with 93 additions and 13 deletions

View File

@ -4,6 +4,8 @@ namespace App\Http\Controllers\Api;
use App\Models\User;
use App\Module\Base;
use Guanguans\Notify\Factory;
use Guanguans\Notify\Messages\EmailMessage;
use Request;
use Response;
@ -566,4 +568,45 @@ class SystemController extends AbstractController
]);
}
/**
* @api {get} api/system/email/check 15. 邮件发送测试(限管理员)
*
* @apiDescription 测试配置邮箱是否能发送邮件
* @apiVersion 1.0.0
* @apiGroup system
* @apiName email__check
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function email__check()
{
User::auth('admin');
//
$all = Request::input();
if (!Base::isEmail($all['to'])) {
return Base::retError('请输入正确的收件人地址');
}
try {
Factory::mailer()
->setDsn("smtp://{$all['account']}:{$all['password']}@{$all['smtp_server']}:{$all['port']}?verify_peer=0")
->setMessage(EmailMessage::create()
->from(env('APP_NAME', 'Task') . " <{$all['account']}>")
->to($all['to'])
->subject('Mail sending test')
->html('<p>收到此电子邮件意味着您的邮箱配置正确。</p><p>Receiving this email means that your mailbox is configured correctly.</p>'))
->send();
return Base::retSuccess('成功发送');
} catch (\Exception $e) {
// 一般是请求超时
if (str_contains($e->getMessage(), "Timed Out")) {
return Base::retError("language.TimedOut");
} elseif ($e->getCode() === 550) {
return Base::retError('邮件内容被拒绝,请检查邮箱是否开启接收功能');
} else {
return Base::retError($e->getMessage());
}
}
}
}

View File

@ -996,13 +996,16 @@ class Base
/**
* 检测邮箱格式
* @param string $str 需要检测的字符串
* @return int
* @param $str
* @return bool
*/
public static function isEmail($str)
{
$RegExp = '/^[a-z0-9][a-z\.0-9-_]+@[a-z0-9_-]+(?:\.[a-z]{0,3}\.[a-z]{0,2}|\.[a-z]{0,3}|\.[a-z]{0,2})$/i';
return preg_match($RegExp, $str);
if (filter_var($str, FILTER_VALIDATE_EMAIL)) {
return true;
} else {
return false;
}
}
/**

View File

@ -1,6 +1,6 @@
{
"name": "DooTask",
"version": "0.12.77",
"version": "0.12.91",
"description": "DooTask is task management system.",
"scripts": {
"start": "./cmd dev",

2
public/js/app.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
public/js/build/349.js vendored Normal file
View File

@ -0,0 +1 @@
"use strict";(self.webpackChunkDooTask=self.webpackChunkDooTask||[]).push([[349],{21225:(t,e,a)=>{a.d(e,{Z:()=>r});var i=a(1519),s=a.n(i)()((function(t){return t[1]}));s.push([t.id,".valid-wrap[data-v-7bd29e80]{align-items:center;display:flex;height:100vh;justify-content:center;width:100vw}.valid-wrap .valid-box[data-v-7bd29e80]{background-color:#fff;border-radius:10px;padding:5px 15px 20px;width:500px}.valid-wrap .valid-box .valid-title[data-v-7bd29e80]{border-bottom:1px solid #e8eaec;line-height:1;padding:14px 16px}.valid-wrap .valid-box .validation-text[data-v-7bd29e80]{color:#333;font-size:14px;padding:10px}",""]);const r=s},94349:(t,e,a)=>{a.r(e),a.d(e,{default:()=>n});const i={data:function(){return{success:!1,error:!1,errorText:this.$L("链接已过期,已重新发送")}},mounted:function(){this.verificationEmail()},methods:{verificationEmail:function(){var t=this;this.$store.dispatch("call",{url:"users/email/verification",data:{code:this.$route.query.code}}).then((function(){t.success=!0,t.error=!1})).catch((function(e){var a=e.data,i=e.msg;2===a.code?t.goForward({name:"index"},!0):(t.success=!1,t.error=!0,t.errorText=t.$L(i))}))},userLogout:function(){this.$store.dispatch("logout",!1)}}};var s=a(93379),r=a.n(s),o=a(21225),d={insert:"head",singleton:!1};r()(o.Z,d);o.Z.locals;const n=(0,a(51900).Z)(i,(function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("div",{staticClass:"valid-wrap"},[a("div",{staticClass:"valid-box"},[a("div",{staticClass:"valid-title"},[t._v(t._s(t.$L("验证邮箱")))]),t._v(" "),t.success||t.error?t._e():a("Spin",{attrs:{size:"large"}}),t._v(" "),t.success?a("div",{staticClass:"validation-text"},[a("p",[t._v(t._s(t.$L("您的邮箱已通过验证")))]),t._v(" "),a("p",[t._v(t._s(t.$L("今后您可以通过此邮箱重置您的账号密码")))])]):t._e(),t._v(" "),t.error?a("div",{staticClass:"validation-text"},[a("div",[t._v(t._s(t.errorText))])]):t._e(),t._v(" "),t.success?a("div",{attrs:{slot:"footer"},slot:"footer"},[a("Button",{attrs:{type:"primary",long:""},on:{click:t.userLogout}},[t._v(t._s(t.$L("返回首页")))])],1):t._e()],1)])}),[],!1,null,"7bd29e80",null).exports}}]);

View File

@ -1 +0,0 @@
"use strict";(self.webpackChunkDooTask=self.webpackChunkDooTask||[]).push([[645],{46080:(t,a,e)=>{e.d(a,{Z:()=>r});var i=e(1519),s=e.n(i)()((function(t){return t[1]}));s.push([t.id,".valid-wrap[data-v-27a2194d]{align-items:center;display:flex;height:100vh;justify-content:center;width:100vw}.valid-wrap .valid-box[data-v-27a2194d]{background-color:#fff;border-radius:10px;padding:5px 15px 20px;width:500px}.valid-wrap .valid-box .valid-title[data-v-27a2194d]{border-bottom:1px solid #e8eaec;line-height:1;padding:14px 16px}.valid-wrap .valid-box .validation-text[data-v-27a2194d]{color:#333;font-size:14px;padding:10px}",""]);const r=s},47645:(t,a,e)=>{e.r(a),e.d(a,{default:()=>n});const i={data:function(){return{success:!1,error:!1,errorText:this.$L("链接已过期,已重新发送")}},mounted:function(){this.verificationEmail()},watch:{},methods:{verificationEmail:function(){var t=this;this.$store.dispatch("call",{url:"users/email/verification",data:{code:this.$route.query.code}}).then((function(){t.success=!0,t.error=!1})).catch((function(a){var e=a.data,i=a.msg;2===e.code?t.goForward({name:"index"},!0):(t.success=!1,t.error=!0,t.errorText=t.$L(i))}))},userLogout:function(){this.$store.dispatch("logout",!1)}}};var s=e(93379),r=e.n(s),o=e(46080),d={insert:"head",singleton:!1};r()(o.Z,d);o.Z.locals;const n=(0,e(51900).Z)(i,(function(){var t=this,a=t.$createElement,e=t._self._c||a;return e("div",{staticClass:"valid-wrap"},[e("div",{staticClass:"valid-box"},[e("div",{staticClass:"valid-title"},[t._v(t._s(t.$L("验证邮箱")))]),t._v(" "),t.success||t.error?t._e():e("Spin",{attrs:{size:"large"}}),t._v(" "),t.success?e("div",{staticClass:"validation-text"},[e("p",[t._v(t._s(t.$L("您的邮箱已通过验证")))]),t._v(" "),e("p",[t._v(t._s(t.$L("今后您可以通过此邮箱重置您的账号密码")))])]):t._e(),t._v(" "),t.error?e("div",{staticClass:"validation-text"},[e("div",[t._v(t._s(t.errorText))])]):t._e(),t._v(" "),t.success?e("div",{attrs:{slot:"footer"},slot:"footer"},[e("Button",{attrs:{type:"primary",long:""},on:{click:t.userLogout}},[t._v(t._s(t.$L("返回首页")))])],1):t._e()],1)])}),[],!1,null,"27a2194d",null).exports}}]);

View File

@ -1 +1 @@
a3af88bf217b5750
815603318bcc7ada

View File

@ -376,7 +376,7 @@
* @returns {boolean}
*/
isEmail(email) {
return /^[a-z0-9][a-z\.0-9-_]+@[a-z0-9_-]+(?:\.[a-z]{0,3}\.[a-z]{0,2}|\.[a-z]{0,3}|\.[a-z]{0,2})$/i.test(email);
return /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*\.)+[a-zA-Z]*)$/i.test(email);
},
/**

View File

@ -10,10 +10,13 @@
<Input :maxlength="20" v-model="formData.port"/>
</FormItem>
<FormItem :label="$L('账号')" prop="account">
<Input :maxlength="20" v-model="formData.account"/>
<Input :maxlength="128" v-model="formData.account"/>
</FormItem>
<FormItem :label="$L('密码')" prop="password">
<Input :maxlength="20" v-model="formData.password" type="password"/>
<Input :maxlength="128" v-model="formData.password" type="password"/>
</FormItem>
<FormItem>
<Button @click="checkEmailSend">{{ $L('邮件发送测试') }}</Button>
</FormItem>
</div>
@ -111,6 +114,7 @@ export default {
this.loadIng--;
});
},
hoursChange(e) {
let newNum = e * 10;
if (newNum % 5 !== 0) {
@ -120,6 +124,7 @@ export default {
$A.messageError('任务提醒只能是0.5的倍数');
}
},
hours2Change(e) {
let newNum = e * 10;
if (newNum % 5 !== 0) {
@ -128,6 +133,36 @@ export default {
})
$A.messageError('第二次任务提醒只能是0.5的倍数');
}
},
checkEmailSend() {
$A.modalInput({
title: "测试邮件",
placeholder: "请输入收件人地址",
onOk: (value, cb) => {
if (!value) {
cb()
return
}
if (!$A.isEmail(value)) {
$A.modalError("请输入正确的收件人地址", 301)
cb()
return
}
this.$store.dispatch("call", {
url: 'system/email/check',
data: Object.assign(this.formData, {
to: value
}),
}).then(({msg}) => {
$A.messageSuccess(msg)
cb()
}).catch(({msg}) => {
$A.modalError(msg, 301)
cb()
});
}
});
}
}
}

View File

@ -57,7 +57,6 @@ export default {
mounted() {
this.verificationEmail();
},
watch: {},
methods: {
verificationEmail() {
this.$store.dispatch("call", {