43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Mail;
|
|
using System.Net.Mime;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ComputerStoreBusinessLogic.MailStuff
|
|
{
|
|
public class MailKit : AbstractMail
|
|
{
|
|
public MailKit(ILogger<MailKit> logger) : base(logger)
|
|
{
|
|
|
|
}
|
|
protected override async Task SendMailAsync(string receiver, MemoryStream report)
|
|
{
|
|
using var objMailMessage = new MailMessage();
|
|
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
|
try
|
|
{
|
|
objMailMessage.From = new MailAddress(_mailLogin);
|
|
objMailMessage.To.Add(new MailAddress(receiver));
|
|
objMailMessage.Subject = "Report";
|
|
objMailMessage.Attachments.Add(new Attachment(report, "ReportProductsPCs.pdf", "application/pdf"));
|
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|