邮件资源释放

parent 8aa2b332
......@@ -91,7 +91,7 @@ public ApiResponse Import([FromForm] IFormCollection form)
var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(file.FileName);
var dpath = Path.Combine(env.ContentRootPath.Substring(0, env.ContentRootPath.LastIndexOf("\\")), "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
var dpath = Path.Combine(env.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
......
......@@ -120,7 +120,7 @@ public ApiResponse Import([FromForm] IFormCollection form)
var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(file.FileName);
var dpath = Path.Combine(_evn.ContentRootPath.Substring(0, _evn.ContentRootPath.LastIndexOf("\\")), "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
var dpath = Path.Combine(_evn.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
......
......@@ -69,7 +69,7 @@ public ApiResponse Import([FromForm] IFormCollection form)
var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(file.FileName);
var dpath = Path.Combine(evn.ContentRootPath.Substring(0, evn.ContentRootPath.LastIndexOf("\\")), "Files", $"{hospitalid}", "first");
var dpath = Path.Combine(evn.ContentRootPath, "Files", $"{hospitalid}", "first");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
......
......@@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
......@@ -79,9 +80,9 @@ public Task<bool> SendAsync(EmailMessage message)
public bool Send(EmailMessage message)
{
MailMessage mail = new MailMessage();
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(options.Account, message.DisplayName);
//多邮箱地址处理
message.To.ForEach(t => mail.To.Add(t));
......@@ -92,7 +93,11 @@ public bool Send(EmailMessage message)
mail.IsBodyHtml = true;//设置为HTML格式
mail.Priority = MailPriority.Low;//优先级
//发送附件 指明附件的绝对地址
message.Attachments.ForEach(t => mail.Attachments.Add(new Attachment(t)));
message.Attachments.ForEach(t =>
{
if (FileHelper.IsExistFile(t))
mail.Attachments.Add(new Attachment(t));
});
SmtpClient client = new SmtpClient(options.SmtpServer, 80);
client.Timeout = 10000;
client.UseDefaultCredentials = true;
......@@ -106,6 +111,11 @@ public bool Send(EmailMessage message)
logger.LogError(ex.ToString());
throw ex;
}
finally
{
if (message.Attachments.Any())
mail.Attachments.Dispose();
}
}
}
......
......@@ -120,7 +120,7 @@ public void ExtractData(int allotId, string mail, sys_hospital hospital)
}
}
LogHelper.Information($"基础数据提取完成,", "提取绩效数据");
var dpath = Path.Combine(environment.ContentRootPath.Substring(0, environment.ContentRootPath.LastIndexOf("\\")), "Files", $"{hospital.ID}", "autoextract");
var dpath = Path.Combine(environment.ContentRootPath, "Files", $"{hospital.ID}", "autoextract");
FileHelper.CreateDirectory(dpath);
string path = Path.Combine(dpath, $"绩效数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx");
//根据SHEET页信息,列头信息,创建EXCEL文件
......@@ -416,7 +416,7 @@ private List<PerSheet> GetRepositoryData(int allotId)
}
return sheetList;
}
/// <summary>
/// 获取sheet及列头
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment