添加项目文件。

This commit is contained in:
Zel
2025-01-22 23:31:03 +08:00
parent 1b8ba6771f
commit 2ae76476fb
894 changed files with 774558 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>2.20.1</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="4.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TightWiki.Repository\TightWiki.Repository.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,56 @@
using MailKit.Net.Smtp;
using MailKit.Security;
using Microsoft.Extensions.Logging;
using MimeKit;
using TightWiki.Library.Interfaces;
using TightWiki.Repository;
namespace TightWiki.Email
{
public class WikiEmailSender : IWikiEmailSender
{
private readonly ILogger<WikiEmailSender> _logger;
public WikiEmailSender(ILogger<WikiEmailSender> logger)
{
_logger = logger;
}
public async Task SendEmailAsync(string email, string subject, string htmlMessage)
{
try
{
var values = ConfigurationRepository.GetConfigurationEntryValuesByGroupName("Email");
var smtpPassword = values.Value<string>("Password");
var smtpUsername = values.Value<string>("Username");
var smtpAddress = values.Value<string>("Address");
var smtpFromDisplayName = values.Value<string>("From Display Name");
var smtpUseSSL = values.Value<bool>("Use SSL");
int smtpPort = values.Value<int>("Port");
if (string.IsNullOrEmpty(smtpAddress) || string.IsNullOrEmpty(smtpUsername))
{
return;
}
var message = new MimeMessage();
message.From.Add(new MailboxAddress(smtpFromDisplayName, smtpUsername));
message.To.Add(new MailboxAddress(email, email));
message.Subject = subject;
message.Body = new TextPart("html") { Text = htmlMessage };
using var client = new SmtpClient();
var options = smtpUseSSL ? SecureSocketOptions.SslOnConnect : SecureSocketOptions.StartTlsWhenAvailable;
await client.ConnectAsync(smtpAddress, smtpPort, options);
await client.AuthenticateAsync(smtpUsername, smtpPassword);
await client.SendAsync(message);
await client.DisconnectAsync(true);
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
ExceptionRepository.InsertException(ex);
}
}
}
}