2024-05-29 17:43:10 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.BusinessLogicsContracts;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Mail;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Security.Authentication;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MailKit.Net.Pop3;
|
|
|
|
|
using MailKit.Security;
|
|
|
|
|
using System.Net.Mime;
|
|
|
|
|
|
|
|
|
|
namespace UniversityBusinessLogic.MailWorker
|
|
|
|
|
{
|
|
|
|
|
public class MailKitWorker : AbstractMailWorker
|
|
|
|
|
{
|
|
|
|
|
public MailKitWorker(ILogger<MailKitWorker> logger) : base(logger) { }
|
|
|
|
|
|
|
|
|
|
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
|
|
|
|
{
|
|
|
|
|
using var objMailMessage = new MailMessage();
|
|
|
|
|
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
objMailMessage.From = new MailAddress(_mailLogin);
|
|
|
|
|
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
|
|
|
|
objMailMessage.Subject = info.Subject;
|
|
|
|
|
objMailMessage.Body = info.Text;
|
|
|
|
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
|
|
|
|
objMailMessage.BodyEncoding = Encoding.UTF8;
|
2024-05-29 21:06:39 +04:00
|
|
|
|
Attachment attachment = new Attachment("C:\\ВременныеОтчёты\\Сведения по планам обучения.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
2024-05-29 17:43:10 +04:00
|
|
|
|
objMailMessage.Attachments.Add(attachment);
|
|
|
|
|
|
|
|
|
|
objSmtpClient.UseDefaultCredentials = false;
|
|
|
|
|
objSmtpClient.EnableSsl = true;
|
|
|
|
|
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
|
|
|
|
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
|
|
|
|
|
|
|
|
|
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|