更新后台smtp发信配置;更新组件

This commit is contained in:
2018-08-28 23:01:14 +08:00
parent 5e0ab0521c
commit 33831222cd
8 changed files with 143 additions and 22 deletions
@@ -11,6 +11,8 @@ using COMCMS.Web.Common;
using COMCMS.Core.Models;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using MimeKit;
using MailKit.Net.Smtp;
namespace COMCMS.Web.Areas.AdminCP.Controllers
{
@@ -116,7 +118,49 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
return Json(tip);
}
/// <summary>
/// 发送测试
/// </summary>
/// <returns></returns>
[HttpPost]
[MyAuthorize("edit", "smptconfig", "JSON")]
public IActionResult SendTestMail()
{
string mail = Request.Form["txtEmail"];
Config cfg = Config.GetSystemConfig();
if (string.IsNullOrWhiteSpace(mail) || !Utils.IsValidEmail(mail))
{
tip.Message = "请输入正确的邮箱格式!";
return Json(tip);
}
var smtp = cfg.SMTPConfigEntity;
if (string.IsNullOrEmpty(smtp.SmtpHost) || string.IsNullOrEmpty(smtp.SmtpEmail) || string.IsNullOrEmpty(smtp.SmtpEmailPwd))
{
tip.Message = "系统SMTP配置错误,请先配置后再执行此操作!";
return Json(tip);
}
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress(smtp.PostUserName, smtp.SmtpEmail));
emailMessage.To.Add(new MailboxAddress("", mail));
emailMessage.Subject = "发送测试邮件";
emailMessage.Body = new TextPart("html") { Text = $"<p>发送测试邮件,发送时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}</p>" };
//同步发送
using (var client = new SmtpClient())
{
client.Connect(smtp.SmtpHost, int.Parse(smtp.SmtpProt), smtp.IsSSL == 1 ? true : false);
client.Authenticate(smtp.SmtpEmail, smtp.SmtpEmailPwd);
client.Send(emailMessage);
client.Disconnect(true);
}
tip.Status = JsonTip.SUCCESS;
tip.Message = "发送成功,请查收!";
Admin.WriteLogActions($"发送测试Email(to:${mail});");
return Json(tip);
}
#endregion
#region 附件配置
@@ -53,7 +53,7 @@
<div class="form-group">
<label class="col-sm-3 control-label">操作详细日志:</label>
<div class="col-sm-8">
<label class="control-label" style="text-align:left">@Model.Actions.Replace("|||","<br />")</label>
<label class="control-label" style="text-align:left">@Html.Raw(Model.Actions.Replace("|||", "<br />"))</label>
</div>
</div>
@@ -17,7 +17,7 @@
<div class="tab-content">
<div id="tab-1" class="tab-pane active">
<div class="panel-body">
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editBaseConfigForm", @class = "form-horizontal m-t" }))
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editSMTPConfigForm", @class = "form-horizontal m-t" }))
{
<div class="form-group">
<label class="col-sm-3 control-label">SMTP服务器:</label>
@@ -44,11 +44,19 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">公司电话:</label>
<label class="col-sm-3 control-label">SMTP身份验证密码:</label>
<div class="col-sm-8">
<input id="SmtpEmailPwd" name="SmtpEmailPwd" maxlength="50" type="text" class="form-control" placeholder="帐号密码" value="@Model.SmtpEmailPwd">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">SSL 连接:</label>
<div class="col-sm-8">
<label class="checkbox-inline i-checks">
<input type="checkbox" value="1" name="IsSSL" id="IsSSL" @(Model.IsSSL == 1 ? "checked = \"checked\"" : "")> SSL连接(一般如果端口是465 则勾选此选项,如果是25端口,则不用勾选此选项)
</label>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
@@ -60,18 +68,20 @@
</div>
<div id="tab-2" class="tab-pane">
<div class="panel-body">
<div class="form-group">
<label class="col-sm-3 control-label">测试收件人:</label>
<div class="col-sm-8">
<input id="txtEmail" name="txtEmail" maxlength="200" type="text" class="form-control" placeholder="请输入一个接收邮箱地址进行测试" value="">
<form asp-action="SendTestMail" asp-area="AdminCP" asp-controller="System" name="sendtestmailForm" id="sendtestmailForm" method="post" class="form-horizontal m-t">
<div class="form-group">
<label class="col-sm-3 control-label">测试收件人:</label>
<div class="col-sm-8">
<input id="txtEmail" name="txtEmail" maxlength="200" type="email" class="form-control" placeholder="请输入一个接收邮箱地址进行测试" value="">
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-primary" type="button" onclick="alert('敬请期待...')"><i class="fa fa-send"></i> 测试发信 </button>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-primary" type="submit"><i class="fa fa-send"></i> 测试发信 </button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
@@ -83,7 +93,8 @@
</div>
<script>
$(function () {
DoPost("editBaseConfigForm");
DoPost("editSMTPConfigForm");
DoPost("sendtestmailForm");
})
</script>