Ejemplo n.º 1
0
        public async Task SendEmailAsync(string userName, string email, SchedulerMessage message)
        {
            var emailMessage = new MimeMessage();

            emailMessage.From.Add(new MailboxAddress("Eternal Store", smtpLogin));
            emailMessage.To.Add(new MailboxAddress(userName, email));
            emailMessage.Subject = message.Subject;
            emailMessage.Body    = new TextPart(MimeKit.Text.TextFormat.Html)
            {
                Text = message.Body
            };

            using var client = new SmtpClient();

            await client.ConnectAsync(smtpAddress, smtpPort, useSsl);

            await client.AuthenticateAsync(smtpLogin, smtpPassword);

            await client.SendAsync(emailMessage);

            await client.DisconnectAsync(true);

            var dbEmailMessage = EmailMessage.Insert(smtpLogin, email, message);
            await emailMessageRepository.InsertAsync(dbEmailMessage);
        }