Beispiel #1
0
        private async Task SendEmailMessage(MimeMessage emailMessage)
        {
            using (var client = new SmtpClient())
            {
                try
                {
                    await client.ConnectAsync(_emailConfig.SmtpServer, _emailConfig.Port, true);

                    client.AuthenticationMechanisms.Remove("XOAUTH2");
                    await client.AutenticateAsync(_emailConfig.Username, _emailConfig.Password);

                    await client.SendAsync(emailMessage);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    await client.DisconnectAsync(true);

                    client.Dispose();
                }
            }
        }