transitition to pc
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user