From ac62427ce7fc88b2d08cecb97fcccd46ce9eb1e6 Mon Sep 17 00:00:00 2001 From: strwbrry1 Date: Thu, 2 Oct 2025 17:03:36 +0400 Subject: [PATCH] transitition to pc --- .../Infrastructure/EmailService.cs | 75 +++++++++---------- .../YAPWebApplication/appsettings.json | 10 ++- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/YouAreProgrammerShop/YAPWebApplication/Infrastructure/EmailService.cs b/YouAreProgrammerShop/YAPWebApplication/Infrastructure/EmailService.cs index b96399c..243fe1c 100644 --- a/YouAreProgrammerShop/YAPWebApplication/Infrastructure/EmailService.cs +++ b/YouAreProgrammerShop/YAPWebApplication/Infrastructure/EmailService.cs @@ -3,46 +3,43 @@ using MimeKit; namespace YAPWebApplication.Infrastructure { - namespace YAPWebApplication.Services + public interface IEmailService { - public interface IEmailService - { - Task SendEmailAsync(string to, string subject, string body, Stream? attachment = null, string? fileName = null); - } - - public class EmailService : IEmailService - { - private readonly IConfiguration _config; - - public EmailService(IConfiguration config) - { - _config = config; - } - - public async Task SendEmailAsync(string to, string subject, string body, Stream? attachment = null, string? fileName = null) - { - var emailMessage = new MimeMessage(); - emailMessage.From.Add(new MailboxAddress("Shop Reports", _config["Email:SmtpUser"])); - emailMessage.To.Add(MailboxAddress.Parse(to)); - emailMessage.Subject = subject; - - var builder = new BodyBuilder { HtmlBody = body }; - - if (attachment != null && fileName != null) - { - attachment.Seek(0, SeekOrigin.Begin); - builder.Attachments.Add(fileName, attachment); - } - - emailMessage.Body = builder.ToMessageBody(); - - using var client = new SmtpClient(); - await client.ConnectAsync(_config["Email:SmtpServer"], int.Parse(_config["Email:SmtpPort"]), true); - await client.AuthenticateAsync(_config["Email:SmtpUser"], _config["Email:SmtpPass"]); - await client.SendAsync(emailMessage); - await client.DisconnectAsync(true); - } - } + Task SendEmailAsync(string to, string subject, string body, Stream? attachment = null, string? fileName = null); } + public class EmailService : IEmailService + { + private readonly IConfiguration _config; + + public EmailService(IConfiguration config) + { + _config = config; + } + + public async Task SendEmailAsync(string to, string subject, string body, Stream? attachment = null, string? fileName = null) + { + var emailMessage = new MimeMessage(); + emailMessage.From.Add(new MailboxAddress("Shop Reports", _config["Email:SmtpUser"])); + emailMessage.To.Add(MailboxAddress.Parse(to)); + emailMessage.Subject = subject; + + var builder = new BodyBuilder { HtmlBody = body }; + + if (attachment != null && fileName != null) + { + attachment.Seek(0, SeekOrigin.Begin); + builder.Attachments.Add(fileName, attachment); + } + + emailMessage.Body = builder.ToMessageBody(); + + using var client = new SmtpClient(); + await client.ConnectAsync(_config["Email:SmtpServer"], int.Parse(_config["Email:SmtpPort"]), true); + await client.AuthenticateAsync(_config["Email:SmtpUser"], _config["Email:SmtpPass"]); + await client.SendAsync(emailMessage); + await client.DisconnectAsync(true); + } + } } + diff --git a/YouAreProgrammerShop/YAPWebApplication/appsettings.json b/YouAreProgrammerShop/YAPWebApplication/appsettings.json index 723b471..a73288a 100644 --- a/YouAreProgrammerShop/YAPWebApplication/appsettings.json +++ b/YouAreProgrammerShop/YAPWebApplication/appsettings.json @@ -26,9 +26,11 @@ "ConnectionString": "Host=127.0.0.1;Port=5432;Database=YAP;Username=postgres;Password=postgres;" }, "Email": { - "SmtpServer": "smtp.gmail.com", - "SmtpPort": "465", - "SmtpUser": "yourmail@gmail.com", - "SmtpPass": "app_password" + "SmtpServer": "smtp.yandex.ru", + "SmtpPort": 465, + "SmtpUser": "saratov.escaper@yandex.ru", + "SmtpPass": "gldtzvjtnfgzhhpu", + "FromName": "YAP Mail Service", + "FromEmail": "saratov.escaper@yandex.ru" } } \ No newline at end of file