From e88d4d24c3584fbbefc720a53e74d1b13b120bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sun, 2 Jan 2022 15:56:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81=E9=82=AE?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommonController.cs | 11 ++- ZR.Common/MailHelper.cs | 58 +++++------ ZR.Tasks/TaskSchedulerServer.cs | 4 +- ZR.Tasks/ZR.Tasks.csproj | 1 - ZR.Vue/src/components/FileUpload/index.vue | 4 +- .../views/system/user/profile/userAvatar.vue | 2 +- ZR.Vue/src/views/tool/email/sendEmail.vue | 97 ++++++++++--------- 7 files changed, 93 insertions(+), 84 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 2122e9e..1cf5167 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -74,7 +74,7 @@ namespace ZR.Admin.WebApi.Controllers { return ToResponse(ApiResult.Error($"请配置邮箱信息")); } - + MailHelper mailHelper = new(); string[] toUsers = sendEmailVo.ToUser.Split(",", StringSplitOptions.RemoveEmptyEntries); @@ -85,7 +85,7 @@ namespace ZR.Admin.WebApi.Controllers mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent); logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}"); - + return SUCCESS(true); } @@ -96,11 +96,12 @@ namespace ZR.Admin.WebApi.Controllers /// /// /// 存储目录 + /// 上传类型 1、发送邮件 /// [HttpPost()] [Verify] [ActionPermissionFilter(Permission = "common")] - public IActionResult UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileDir = "uploads") + public IActionResult UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileDir = "uploads", int uploadType = 0) { if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空"); string fileExt = Path.GetExtension(formFile.FileName); @@ -137,7 +138,7 @@ namespace ZR.Admin.WebApi.Controllers long fileId = SysFileService.InsertFile(file); return ToResponse(ResultCode.SUCCESS, new { - url = accessPath, + url = uploadType == 1 ? finalFilePath : accessPath, fileName, fileId }); @@ -168,7 +169,7 @@ namespace ZR.Admin.WebApi.Controllers { return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + (MaxContentLength / 1024).ToString() + " MB"); } - + (bool, string, string) result = SysFileService.SaveFile(fileDir, formFile); long fileId = SysFileService.InsertFile(new SysFile() { diff --git a/ZR.Common/MailHelper.cs b/ZR.Common/MailHelper.cs index 4555895..d05ef85 100644 --- a/ZR.Common/MailHelper.cs +++ b/ZR.Common/MailHelper.cs @@ -30,7 +30,7 @@ namespace ZR.Common /// 是否使用SSL协议 /// public bool UseSsl { get; set; } = false; - public string mailSign = @""; + public string mailSign = @"邮件来自C# 程序发送"; private readonly MailOptions mailOptions = new(); public MailHelper() @@ -93,9 +93,10 @@ namespace ZR.Common /// 发送邮件 /// /// - /// + /// 主题 /// /// 附件url地址 + /// 网页HTML内容 private void SendMail(IEnumerable toAddress, string subject, string text, string path = "", string html = "") { MimeMessage message = new MimeMessage(); @@ -131,39 +132,40 @@ namespace ZR.Common //附件 if (!string.IsNullOrEmpty(path)) { - MimePart attachment = new MimePart() + string[] files = path.Split(","); + foreach (var file in files) { - Content = new MimeContent(File.OpenRead(path), ContentEncoding.Default), - //读取文件,只能用绝对路径 - ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), - ContentTransferEncoding = ContentEncoding.Base64, - //文件名字 - FileName = Path.GetFileName(path) - }; - alternative.Add(attachment); + MimePart attachment = new() + { + Content = new MimeContent(File.OpenRead(file), ContentEncoding.Default), + //读取文件,只能用绝对路径 + ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), + ContentTransferEncoding = ContentEncoding.Base64, + //文件名字 + FileName = Path.GetFileName(path) + }; + alternative.Add(attachment); + } } multipart.Add(alternative); //赋值邮件内容 message.Body = multipart; - + //开始发送 - using (var client = new SmtpClient()) - { - client.ServerCertificateValidationCallback = (s, c, h, e) => true; - - //Smtp服务器 - //client.Connect("smtp.qq.com", 587, false); - client.Connect(Smtp, Port, true); - //登录,发送 - //特别说明,对于服务器端的中文相应,Exception中有编码问题,显示乱码了 - client.Authenticate(FromEmail, FromPwd); + using var client = new SmtpClient(); + client.ServerCertificateValidationCallback = (s, c, h, e) => true; - client.Send(message); - //断开 - client.Disconnect(true); - Console.WriteLine($"发送邮件成功{DateTime.Now}"); - } + //Smtp服务器 + //client.Connect("smtp.qq.com", 587, false); + client.Connect(Smtp, Port, true); + //登录,发送 + //特别说明,对于服务器端的中文相应,Exception中有编码问题,显示乱码了 + client.Authenticate(FromEmail, FromPwd); + + client.Send(message); + //断开 + client.Disconnect(true); + Console.WriteLine($"发送邮件成功{DateTime.Now}"); } - } } \ No newline at end of file diff --git a/ZR.Tasks/TaskSchedulerServer.cs b/ZR.Tasks/TaskSchedulerServer.cs index d261ca9..4be4403 100644 --- a/ZR.Tasks/TaskSchedulerServer.cs +++ b/ZR.Tasks/TaskSchedulerServer.cs @@ -55,7 +55,7 @@ namespace ZR.Tasks //{ "quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"}, //{ "quartz.jobStore.useProperties", "true"}, //{ "quartz.jobStore.dataSource", "myDS" }, - //{ "quartz.dataSource.myDS.connectionString", @"server=118.24.27.111;port=3306;database=zrryAdmin;uid=zrry;pwd=@zrry1993^Hz;Charset=utf8;"}, + //{ "quartz.dataSource.myDS.connectionString", @"server=xxx.xxx.xxx.xxx;port=3306;database=Admin;uid=zrry;pwd=********;Charset=utf8;"}, //{ "quartz.dataSource.myDS.provider", "MySql" }, }; @@ -277,7 +277,7 @@ namespace ZR.Tasks //防止创建时存在数据问题 先移除,然后在执行创建操作 await _scheduler.Result.DeleteJob(jobKey); } - await AddTaskScheduleAsync(tasksQz); + //await AddTaskScheduleAsync(tasksQz); return ApiResult.Success("修改计划成功"); } catch (Exception ex) diff --git a/ZR.Tasks/ZR.Tasks.csproj b/ZR.Tasks/ZR.Tasks.csproj index 6341468..4276868 100644 --- a/ZR.Tasks/ZR.Tasks.csproj +++ b/ZR.Tasks/ZR.Tasks.csproj @@ -11,7 +11,6 @@ - diff --git a/ZR.Vue/src/components/FileUpload/index.vue b/ZR.Vue/src/components/FileUpload/index.vue index f314765..fecc8ee 100644 --- a/ZR.Vue/src/components/FileUpload/index.vue +++ b/ZR.Vue/src/components/FileUpload/index.vue @@ -156,12 +156,12 @@ export default { return; } this.msgSuccess("上传成功"); - this.fileList.push({ name: res.data.fileName, url: res.data.url }); + this.fileList.push({ name: res.data.fileName, url: res.data.url, path: res.data.path }); this.$emit("input", this.column, this.listToString(this.fileList)); }, // 上传进度 uploadProcess(event, file, fileList) { - console.log("上传进度" + file.percentage); + // console.log("上传进度" + file.percentage); }, // 删除文件 handleDelete(index) { diff --git a/ZR.Vue/src/views/system/user/profile/userAvatar.vue b/ZR.Vue/src/views/system/user/profile/userAvatar.vue index 69b2661..9c30a63 100644 --- a/ZR.Vue/src/views/system/user/profile/userAvatar.vue +++ b/ZR.Vue/src/views/system/user/profile/userAvatar.vue @@ -9,7 +9,7 @@
- +
diff --git a/ZR.Vue/src/views/tool/email/sendEmail.vue b/ZR.Vue/src/views/tool/email/sendEmail.vue index 3c5df0e..5a1d414 100644 --- a/ZR.Vue/src/views/tool/email/sendEmail.vue +++ b/ZR.Vue/src/views/tool/email/sendEmail.vue @@ -1,15 +1,12 @@