Beispiel #1
0
        public async Task <OperationResult> TestEmailConfig(TestEmailConfigModel model)
        {
            try
            {
                using (SmtpClient client = new SmtpClient())
                {
                    var message = new MimeMessage();
                    message.From.Add(new MailboxAddress(model.EmailAddress, model.EmailAddress));
                    message.To.Add(new MailboxAddress(model.EmailAddress, model.EmailAddress));
                    message.Subject = "Test Email";

                    message.Body = new TextPart("plain")
                    {
                        Text = @"Hello world!"
                    };

                    await client.ConnectAsync(model.Server, model.Port, false);

                    client.AuthenticationMechanisms.Remove("XOAUTH2");

                    // Note: only needed if the SMTP server requires authentication
                    client.Authenticate(model.User, model.Password);

                    await client.SendAsync(message);

                    await client.DisconnectAsync(true);

                    return(new OperationResult());
                }
            }
            catch (Exception ex)
            {
                return(OperationResult.Failure(ex.Message));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> TestEmailConfig([FromBody] EmailConfigModel model)
        {
            if (model == null)
            {
                return(InvalidRequest());
            }

            var testEmailConfigModel = new TestEmailConfigModel
            {
                EmailAddress = model.SmtpEmailAddress,
                Password     = model.SmtpPassword,
                Port         = model.SmtpPort,
                Server       = model.SmtpServer,
                User         = model.SmtpUser,
                EnableSSL    = model.SmtpEnableSSL
            };

            var result = await this.EmailService.TestEmailConfig(testEmailConfigModel);

            if (result.Success)
            {
                return(this.Success());
            }
            else
            {
                return(this.Error(result.ErrorMessage));
            }
        }