mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: email verification via smtp
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using MailKit.Net.Smtp;
|
||||
using MailKit.Security;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MimeKit;
|
||||
using SharpbinV3.Server.Settings;
|
||||
|
||||
namespace SharpbinV3.Server.Services
|
||||
{
|
||||
public class EmailService(IOptions<EmailSettings> emailSettings)
|
||||
{
|
||||
private readonly EmailSettings settings = emailSettings.Value;
|
||||
|
||||
public async Task SendAsync(string to, string subject, string body)
|
||||
{
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress("Sharpbin", settings.From));
|
||||
message.To.Add(MailboxAddress.Parse(to));
|
||||
message.Subject = subject;
|
||||
|
||||
message.Body = new TextPart("html") { Text = body };
|
||||
|
||||
using var smtp = new SmtpClient();
|
||||
await smtp.ConnectAsync(settings.Host, settings.Port, SecureSocketOptions.StartTls);
|
||||
|
||||
await smtp.AuthenticateAsync(settings.User, settings.Password);
|
||||
|
||||
await smtp.SendAsync(message);
|
||||
await smtp.DisconnectAsync(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user