继续增加发邮件的日志

This commit is contained in:
嬴政 时
2026-03-13 16:33:10 +08:00
parent 61c9fd20a9
commit f5c0211b60
2 changed files with 15 additions and 1 deletions
+14
View File
@@ -229,6 +229,7 @@ namespace YLErp.MailKit
// 创建一个HttpClient实例
using (var httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromMinutes(3); // 根据需要调整
var content = new MultipartFormDataContent();
// 添加收件人
content.Add(new StringContent(string.Join(",", option.MailTo)), "to");
@@ -276,6 +277,10 @@ namespace YLErp.MailKit
}
}
}
if (log != null) {
log.Invoke("邮件发送接口", "BaseUrl:" + baseUrl);
log.Invoke("邮件发送接口", "EmailPath:" + emailPath);
}
// 发送POST请求
var response = httpClient.PostAsync($"{baseUrl}{emailPath}", content).Result;
@@ -284,6 +289,10 @@ namespace YLErp.MailKit
{
// 解析响应内容并返回结果
var result = response.Content.ReadAsStringAsync().Result;
if (log != null)
{
log.Invoke("邮件发送接口", "响应内容:" + result);
}
if (string.IsNullOrEmpty(result))
{
throw new ArgumentException("发送邮件失败");
@@ -297,6 +306,11 @@ namespace YLErp.MailKit
}
else
{
if (log != null)
{
log.Invoke("邮件发送接口", "响应状态码:" + response.StatusCode);
log.Invoke("邮件发送接口", "响应内容:" + response.Content.ReadAsStringAsync().Result);
}
// 处理错误情况
}
}
+1 -1
View File
@@ -80,7 +80,7 @@ namespace YLErp.Helpers
IsBodyHtml = isBodyHtml,
FilesToAttach = filesToAttach,
CC = ccEmail
});
}, (name, info) => { LogFactory.GetLogger(name).Info(info); });
LogFactory.GetLogger("邮件发送").Info($"邮件发送完成,mailTo={mailTo},subject={subject},result={result}");
return string.Empty;
}