Example #1
0
        public void Test(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var config = ToSmtpSettingsConfig(settings);

            using (var smtpClient = new SmtpClient(config.Host, config.Port))
            {
                smtpClient.Timeout        = (int)TimeSpan.FromSeconds(10).TotalMilliseconds;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.EnableSsl      = config.EnableSSL;

                if (config.IsRequireAuthentication)
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials           = new NetworkCredential(config.CredentialsUserName, config.CredentialsUserPassword);
                }

                var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
                var toAddress   = new MailAddress(currentUser.Email);
                var fromAddress = new MailAddress(config.SenderAddress, config.SenderDisplayName);
                var mailMessage = new MailMessage(fromAddress, toAddress)
                {
                    Subject = Core.Notify.WebstudioPatternResource.subject_smtp_test,
                    Body    = Core.Notify.WebstudioPatternResource.pattern_smtp_test
                };

                smtpClient.Send(mailMessage);
            }
        }
        public void Test(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var config = ToSmtpSettingsConfig(settings);

            using (var smtpClient = new SmtpClient(config.Host, config.Port))
            {
                smtpClient.Timeout = (int)TimeSpan.FromSeconds(10).TotalMilliseconds;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.EnableSsl = config.EnableSSL;

                if (config.IsRequireAuthentication)
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = new NetworkCredential(config.CredentialsUserName, config.CredentialsUserPassword);
                }

                var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
                var toAddress = new MailAddress(currentUser.Email);
                var fromAddress = new MailAddress(config.SenderAddress, config.SenderDisplayName);
                var mailMessage = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = Core.Notify.WebstudioPatternResource.subject_smtp_test,
                        Body = Core.Notify.WebstudioPatternResource.pattern_smtp_test
                    };

                smtpClient.Send(mailMessage);
            }
        }
Example #3
0
        public static bool Send(SimpleEmailModel message, SmtpSettingsModel smtp)
        {
            var mail   = new MailMessage(smtp.Sender, smtp.Sender);
            var client = new SmtpClient
            {
                Port                  = int.Parse(smtp.Port),
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new System.Net.NetworkCredential(smtp.Username, smtp.Password),
                Host                  = smtp.Provider
            };

            mail.Subject = message.Subject;
            mail.Body    = message.Body;
            mail.To.Add(message.To);
            mail.IsBodyHtml = true;
            try
            {
                client.Send(mail);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(false);
        }
Example #4
0
 public PapercutSmtpService()
 {
     SmtpSettings             = new SmtpSettingsModel();
     SmtpSettings.HostUrl     = "localhost";
     SmtpSettings.Port        = 25;
     SmtpSettings.EnableSsl   = false;
     SmtpSettings.FromAddress = "*****@*****.**";
 }
Example #5
0
 private void Initialize()
 {
     SmtpSettings = new SmtpSettingsModel();
     //host url
     //port
     //ssl enabled
     //api key / password
     //from address
 }
        public SmtpSettingsModel Save(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var smtpSettings = ToSmtpSettingsConfig(settings);

            CoreContext.Configuration.SmtpSettings = smtpSettings;
            return(ToSmtpSettingsModel(smtpSettings));
        }
Example #7
0
        public OutlookSmptService()
        {
            SmtpSettings = new SmtpSettingsModel();

            SmtpSettings.FromAddress      = "*****@*****.**";
            SmtpSettings.HostUrl          = "smtp.office365.com";
            SmtpSettings.Port             = 587;
            SmtpSettings.EnableSsl        = true;
            SmtpSettings.ApiKeyOrPassword = "";
        }
Example #8
0
        public GmailSmptService()
        {
            SmtpSettings = new SmtpSettingsModel();

            SmtpSettings.HostUrl          = "smtp.gmail.com";
            SmtpSettings.Port             = 587;
            SmtpSettings.EnableSsl        = true;
            SmtpSettings.ApiKeyOrPassword = "";
            SmtpSettings.FromAddress      = "*****@*****.**";
        }
Example #9
0
        public async Task <Tuple <string, bool> > SendPasswordResetLink(string userName)
        {
            bool   isUserExists = false;
            string token        = string.Empty;
            string url          = string.Empty;

            var companySettings = _appDbContext.CompanySettings.FirstOrDefault();

            if (companySettings == null)
            {
                return(new Tuple <string, bool>("Failed to send password reset link", false));
            }

            ApplicationUser user = _userManager.FindByNameAsync(userName).Result;

            if (user != null)
            {
                if (user.PasswordHash == null)
                {
                    IdentityResult isSuccess = _userManager.AddPasswordAsync(user, "Test@1234").Result;
                    await _userManager.AddToRoleAsync(user, "Admin");
                }
                token        = _userManager.GeneratePasswordResetTokenAsync(user).Result;
                isUserExists = true;
                url          = "<a href =" + string.Format($"{HostSettings.RequestSchema}://{HostSettings.Host}/reset-password?token={{0}}&userId={{1}}", System.Web.HttpUtility.UrlEncode(token), user.Id) + " target=\"_blank\">password</a>";
            }

            if (isUserExists)
            {
                companySettings.PasswordResetEmailMessage = companySettings.PasswordResetEmailMessage.Contains("{url}") ? companySettings.PasswordResetEmailMessage.Replace("{url}", url) : companySettings.InvitationEmailMessage;
                companySettings.PasswordResetEmailMessage = companySettings.PasswordResetEmailMessage.Contains("{name}") ? companySettings.PasswordResetEmailMessage.Replace("{name}", user.FirstName + " " + user.LastName) : companySettings.PasswordResetEmailMessage;

                SmtpSettingsModel smtpSettingsModel = new SmtpSettingsModel
                {
                    EmailMessage       = companySettings.PasswordResetEmailMessage,
                    EmailSubject       = companySettings.PasswordResetEmailSubject,
                    EncryptionType     = companySettings.SmtpencrcyptionType,
                    SMTPAuthentication = companySettings.Smtpauthentication,
                    SMTPFromEmail      = companySettings.SmtpfromEmail,
                    SMTPFromName       = companySettings.SmtpfromName,
                    SMTPHostUrl        = companySettings.Smtphost,
                    SMTPPassword       = companySettings.Smtppassword,
                    SMTPPort           = companySettings.Smtpport,
                    SMTPUserName       = companySettings.Smtpusername
                };

                _emailService.Send(new List <string>()
                {
                    userName
                }, null, null, smtpSettingsModel);
            }

            return(new Tuple <string, bool>(ResponseMessageModel.UserAccount.PasswordResetLink, isUserExists));
        }
Example #10
0
        private static Task TestMail()
        {
            SmtpSettingsModel smtpSettingsModel = new SmtpSettingsModel("*****@*****.**", "*****@*****.**", "Pawl", "password", "smtp.gmail.com", 587, true);

            MailMessageModel mailMessageModel = new MailMessageModel("[email protected],[email protected]", "Test", "Testowy", true, new[] { @"D:\Downloads\teekst.txt", @"D:\Downloads\teekst2.txt" });


            IMailServiceAsyncTask mailService = new MailServiceAsyncTask(new TraceLogger(new LogMessageFactory()));


            return(mailService.SendEmailAsyncTask(mailMessageModel, smtpSettingsModel));
        }
Example #11
0
        private void PrepareSending(ref SmtpSettingsModel smtpSettingsModel)
        {
            if (this.smtpSettingsModel != null) // Zostało przekazane proprzez konstruktor
            {
                smtpSettingsModel = this.smtpSettingsModel;
            }
            else if (smtpSettingsModel == null) // Nie zostało przekazane proprzez konstruktor i poprzez metodę
            {
                var appSettings = ConfigurationManager.AppSettings;

                smtpSettingsModel = new SmtpSettingsModel(appSettings);
            }
        }
Example #12
0
        public async Task <IActionResult> SmtpSettings(
            int tenantId,
            [Bind(
                 nameof(SmtpSettingsModel.SmtpHost),
                 nameof(SmtpSettingsModel.SmtpPassword),
                 nameof(SmtpSettingsModel.SmtpPort),
                 nameof(SmtpSettingsModel.SmtpUser),
                 nameof(SmtpSettingsModel.ConfirmSmtpPassword)
                 )]
            SmtpSettingsModel m)
        {
            var tenant = await GetTenantAsync(tenantId);

            if (tenant == null)
            {
                return(NotFound());
            }
            SetHeroLayoutViewData(tenant, PageKeys.SmtpSettings);

            if (ModelState.IsValid)
            {
                try
                {
                    tenant.TenantSettings.Smtp.SmtpHost = m.SmtpHost;
                    if (m.SmtpPassword != AspHelpers.UntouchedPassword)
                    {
                        tenant.TenantSettings.Smtp.SmtpPassword = m.SmtpPassword;
                    }
                    tenant.TenantSettings.Smtp.SmtpPort = m.SmtpPort;
                    tenant.TenantSettings.Smtp.SmtpUser = m.SmtpHost;
                    tenant.TenantSettings.Smtp          = new SmtpOptions(m);
                    Rdb.Update(tenant);
                    await Rdb.SaveChangesAsync();

                    SetToast(AspHelpers.ToastMessages.Saved);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TenantExists(tenant.TenantId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(ActionNames.TenantEdit));
            }
            return(View(m));
        }
Example #13
0
        private static SmtpSettingsConfig ToSmtpSettingsConfig(SmtpSettingsModel settingsModel)
        {
            var settingsConfig = new SmtpSettingsConfig(settingsModel.Host, settingsModel.Port ?? SmtpSettingsConfig.DefaultSmtpPort,
                                                        settingsModel.SenderAddress, settingsModel.SenderDisplayName)
            {
                EnableSSL = settingsModel.EnableSSL
            };

            if (!string.IsNullOrEmpty(settingsModel.CredentialsUserName) && !string.IsNullOrEmpty(settingsModel.CredentialsUserPassword))
            {
                settingsConfig.SetCredentials(settingsModel.CredentialsUserName, settingsModel.CredentialsUserPassword);
            }

            return(settingsConfig);
        }
Example #14
0
        public void Test(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var config = ToSmtpSettingsConfig(settings);

            var smtpClient = new SmtpClient(config.Host, config.Port) {EnableSsl = config.EnableSSL};
            if (config.IsRequireAuthentication)
            {
                smtpClient.Credentials = new NetworkCredential(config.CredentialsUserName, config.CredentialsUserPassword);
            }

            var fromAddress = new MailAddress(config.SenderAddress, config.SenderDisplayName);
            var toAddress = new MailAddress("*****@*****.**"); // fake address
            smtpClient.Send(new MailMessage(fromAddress, toAddress));
        }
        public SmtpSettingsModel Save(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var smtpSettings = ToSmtpSettingsConfig(settings);

            CoreContext.Configuration.SmtpSettings = smtpSettings;
            var result = ToSmtpSettingsModel(smtpSettings);

            result.CredentialsUserPassword = "";
            if (string.IsNullOrEmpty(result.SenderDisplayName))
            {
                result.SenderDisplayName = SmtpSettingsConfig.DefaultSenderDisplayName;
            }

            return(result);
        }
Example #16
0
        public async Task <bool> SendInvite(InviteCustomerModel inviteCustomerModel)
        {
            var companySettings = _appDbContext.CompanySettings.FirstOrDefault();

            if (companySettings == null)
            {
                return(false);
            }

            (bool isSuccess, ApplicationUser user) = await CreateUser(inviteCustomerModel);

            string url = string.Empty;

            if (isSuccess)
            {
                url = "<a href =" + string.Format($"{HostSettings.RequestSchema}://{HostSettings.Host}/add-password?userId={{0}}", user.Id) + " target=\"_blank\">Neela</a>";

                companySettings.InvitationEmailMessage = companySettings.InvitationEmailMessage.Contains("{url}") ? companySettings.InvitationEmailMessage.Replace("{url}", url) : companySettings.InvitationEmailMessage;
                companySettings.InvitationEmailMessage = companySettings.InvitationEmailMessage.Contains("{name}") ? companySettings.InvitationEmailMessage.Replace("{name}", user.FirstName + " " + user.LastName) : companySettings.InvitationEmailMessage;


                SmtpSettingsModel smtpSettingsModel = new SmtpSettingsModel
                {
                    EmailMessage       = companySettings.InvitationEmailMessage,
                    EmailSubject       = companySettings.InvitationEmailSubject,
                    EncryptionType     = companySettings.SmtpencrcyptionType,
                    SMTPAuthentication = companySettings.Smtpauthentication,
                    SMTPFromEmail      = companySettings.SmtpfromEmail,
                    SMTPFromName       = companySettings.SmtpfromName,
                    SMTPHostUrl        = companySettings.Smtphost,
                    SMTPPassword       = companySettings.Smtppassword,
                    SMTPPort           = companySettings.Smtpport,
                    SMTPUserName       = companySettings.Smtpusername
                };

                _emailService.Send(new List <string>()
                {
                    inviteCustomerModel.Email
                }, null, null, smtpSettingsModel);
            }
            return(isSuccess);
        }
        public void Test(SmtpSettingsModel settings)
        {
            if (!SetupInfo.IsVisibleSettings(ManagementType.SmtpSettings.ToString()))
            {
                throw new BillingException(Resource.ErrorNotAllowedOption, "Smtp");
            }

            var config = ToSmtpSettingsConfig(settings ?? CurrentSmtpSettings);

            if (config.EnableAuth && config.CredentialsUserPassword.Equals(FakePassword))
            {
                var model = ToSmtpSettingsModel(config);
                model.CredentialsUserPassword = FullSmtpSettings.CredentialsUserPassword;
                config = ToSmtpSettingsConfig(model);
            }

            using (var smtpClient = new SmtpClient(config.Host, config.Port))
            {
                smtpClient.Timeout        = (int)TimeSpan.FromSeconds(10).TotalMilliseconds;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.EnableSsl      = config.EnableSSL;

                if (config.EnableAuth)
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials           = new NetworkCredential(config.CredentialsUserName,
                                                                             config.CredentialsUserPassword);
                }

                var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
                var toAddress   = new MailAddress(currentUser.Email);
                var fromAddress = new MailAddress(config.SenderAddress, config.SenderDisplayName);
                var mailMessage = new MailMessage(fromAddress, toAddress)
                {
                    Subject = Core.Notify.WebstudioNotifyPatternResource.subject_smtp_test,
                    Body    = Core.Notify.WebstudioNotifyPatternResource.pattern_smtp_test
                };

                smtpClient.Send(mailMessage);
            }
        }
        public void Test(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var config = ToSmtpSettingsConfig(settings);

            using (var smtpClient = new SmtpClient(config.Host, config.Port))
            {
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.EnableSsl = config.EnableSSL;
                if (config.IsRequireAuthentication)
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = new NetworkCredential(config.CredentialsUserName, config.CredentialsUserPassword);
                }

                var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
                var toAddress = new MailAddress(currentUser.Email);
                var fromAddress = new MailAddress(config.SenderAddress, config.SenderDisplayName);
                smtpClient.Send(new MailMessage(fromAddress, toAddress));
            }
        }
Example #19
0
        public void Test(SmtpSettingsModel settings)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var config = ToSmtpSettingsConfig(settings);

            using (var smtpClient = new SmtpClient(config.Host, config.Port))
            {
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.EnableSsl      = config.EnableSSL;
                if (config.IsRequireAuthentication)
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials           = new NetworkCredential(config.CredentialsUserName, config.CredentialsUserPassword);
                }

                var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
                var toAddress   = new MailAddress(currentUser.Email);
                var fromAddress = new MailAddress(config.SenderAddress, config.SenderDisplayName);
                smtpClient.Send(new MailMessage(fromAddress, toAddress));
            }
        }
 public void Save(SmtpSettingsModel settings)
 {
     SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
     CoreContext.Configuration.SmtpSettings = ToSmtpSettingsConfig(settings);
 }
        private static SmtpSettingsConfig ToSmtpSettingsConfig(SmtpSettingsModel settingsModel)
        {
            var settingsConfig = new SmtpSettingsConfig(settingsModel.Host, settingsModel.Port ?? SmtpSettingsConfig.DefaultSmtpPort,
                                                        settingsModel.SenderAddress, settingsModel.SenderDisplayName)
                {
                    EnableSSL = settingsModel.EnableSSL
                };

            if (!string.IsNullOrEmpty(settingsModel.CredentialsUserName) && !string.IsNullOrEmpty(settingsModel.CredentialsUserPassword))
            {
                settingsConfig.SetCredentials(settingsModel.CredentialsUserName, settingsModel.CredentialsUserPassword);
            }
            
            return settingsConfig;
        }
Example #22
0
        public JsonResult SmtpSettings_Read()
        {
            GetGeneralResponse <SmtpSettingsModel> smtpResponse = new GetGeneralResponse <SmtpSettingsModel>();

            #region Check Access
            bool hasPermission = GetEmployee().IsGuaranteed("SmtpSettings_Read");
            if (!hasPermission)
            {
                smtpResponse.ErrorMessages.Add("AccessDenied");
                return(Json(smtpResponse, JsonRequestBehavior.AllowGet));
            }
            #endregion

            SmtpSettingsModel smtpSettings = new SmtpSettingsModel();


            #region to Read from a file

            //XmlSerializer reader = new XmlSerializer(typeof(SmtpSettingsModel));

            //try
            //{
            //    string path = Server.MapPath("~/config/xm.xml");
            //    StreamReader file = new StreamReader(path);

            //    smtp = (SmtpSettingsModel)reader.Deserialize(file);
            //    file.Close();
            //}
            //catch (Exception ex)
            //{
            //    return Json(ex.Message, JsonRequestBehavior.AllowGet);
            //}

            #endregion

            #region to read from Web.config

            try
            {
                Configuration            configurationFile = WebConfigurationManager.OpenWebConfiguration("~");
                MailSettingsSectionGroup mailSettings      = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;

                if (mailSettings != null)
                {
                    smtpSettings.EnableSsl = mailSettings.Smtp.Network.EnableSsl;
                    smtpSettings.Host      = mailSettings.Smtp.Network.Host;
                    smtpSettings.Password  = mailSettings.Smtp.Network.Password;
                    smtpSettings.Port      = mailSettings.Smtp.Network.Port;
                    smtpSettings.UserName  = mailSettings.Smtp.Network.UserName;
                }
            }
            catch (Exception ex)
            {
                return(Json(smtpResponse, JsonRequestBehavior.AllowGet));
            }

            #endregion

            smtpResponse.data = smtpSettings;

            return(Json(smtpResponse, JsonRequestBehavior.AllowGet));
        }
Example #23
0
        public JsonResult SmtpSettings_Insert(SmtpSettingsModel smtpSettings)
        {
            GeneralResponse response = new GeneralResponse();

            #region Check Access
            bool hasPermission = GetEmployee().IsGuaranteed("SmtpSettings_Insert");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            #endregion

            #region if we want to Save into a file

            //try
            //{
            //    XmlSerializer writer = new XmlSerializer(typeof(SmtpSettingsModel));

            //    string path = Server.MapPath("~/config/xm.xml");
            //    StreamWriter file = new StreamWriter(path);
            //    writer.Serialize(file, smtpSettings);
            //    file.Close();

            //    hasCenter = true;
            //}
            //catch (Exception ex)
            //{
            //    hasCenter = false;
            //    return Json(ex.Message, JsonRequestBehavior.AllowGet);
            //}

            #endregion

            #region if we want to Save into Web.config

            try
            {
                Configuration            configurationFile = WebConfigurationManager.OpenWebConfiguration("~");
                MailSettingsSectionGroup mailSettings      = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;

                if (mailSettings != null)
                {
                    mailSettings.Smtp.Network.EnableSsl = smtpSettings.EnableSsl;
                    mailSettings.Smtp.Network.Host      = smtpSettings.Host;
                    mailSettings.Smtp.Network.Password  = smtpSettings.Password;
                    mailSettings.Smtp.Network.Port      = smtpSettings.Port;
                    mailSettings.Smtp.Network.UserName  = smtpSettings.UserName;

                    configurationFile.Save();
                }
            }
            catch (Exception ex)
            {
                //response.success = false;
                response.ErrorMessages.Add("SaveChangesProblemKey");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            #endregion

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #24
0
        protected Tuple <MailMessage, SmtpClient> GetData(MailMessageModel mailMessageModel, SmtpSettingsModel smtpSettingsModel)
        {
            PrepareSending(ref smtpSettingsModel);

            var message = mailMessageModel.GetMailMessage(smtpSettingsModel);

            var client = smtpSettingsModel.GetSmtpClient();

            return(Tuple.Create(message, client));
        }
Example #25
0
        protected SmtpClient GetSmtpClient(SmtpSettingsModel smtpSettingsModel)
        {
            PrepareSending(ref smtpSettingsModel);

            return(smtpSettingsModel.GetSmtpClient());
        }
Example #26
0
        public void SendEmailAsync(MailMessage message, SmtpSettingsModel smtpSettingsModel = null)
        {
            var client = GetSmtpClient(smtpSettingsModel);

            SendEmailAsync(message, client);
        }
Example #27
0
        public Task SendEmailAsyncTask(MailMessageModel mailMessageModel, SmtpSettingsModel smtpSettingsModel = null)
        {
            var data = GetData(mailMessageModel, smtpSettingsModel);

            return(SendEmailAsyncTask(data.Item1, data.Item2));
        }
Example #28
0
 public void Save(SmtpSettingsModel settings)
 {
     SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
     CoreContext.Configuration.SmtpSettings = ToSmtpSettingsConfig(settings);
 }
Example #29
0
        public Task SendEmailAsyncTask(MailMessage message, SmtpSettingsModel smtpSettingsModel = null)
        {
            var client = GetSmtpClient(smtpSettingsModel);

            return(SendEmailAsyncTask(message, client));
        }
Example #30
0
 public MailServiceAsync(SmtpSettingsModel smtpSettingsModel, ILogger logger) : base(smtpSettingsModel, logger)
 {
 }
Example #31
0
        public void Test(SmtpSettingsModel settings)
        {
            if (!SetupInfo.IsVisibleSettings(ManagementType.SmtpSettings.ToString()))
            {
                throw new BillingException(Resource.ErrorNotAllowedOption, "Smtp");
            }

            var config = ToSmtpSettingsConfig(settings ?? CurrentSmtpSettings);

            if (config.EnableAuth && config.CredentialsUserPassword.Equals(FakePassword))
            {
                var model = ToSmtpSettingsModel(config);
                model.CredentialsUserPassword = FullSmtpSettings.CredentialsUserPassword;
                config = ToSmtpSettingsConfig(model);
            }

            var sslCertificatePermit = ConfigurationManager.AppSettings["mail.certificate-permit"] != null &&
                                       Convert.ToBoolean(ConfigurationManager.AppSettings["mail.certificate-permit"]);

            var currentUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
            var toAddress   = new MailboxAddress(currentUser.UserName, currentUser.Email);
            var fromAddress = new MailboxAddress(config.SenderDisplayName, config.SenderAddress);

            var mimeMessage = new MimeMessage
            {
                Subject = Core.Notify.WebstudioNotifyPatternResource.subject_smtp_test
            };

            mimeMessage.From.Add(fromAddress);

            mimeMessage.To.Add(toAddress);

            var bodyBuilder = new MimeKit.BodyBuilder
            {
                TextBody = Core.Notify.WebstudioNotifyPatternResource.pattern_smtp_test
            };

            mimeMessage.Body = bodyBuilder.ToMessageBody();

            mimeMessage.Headers.Add("Auto-Submitted", "auto-generated");

            using (var client = new MailKit.Net.Smtp.SmtpClient
            {
                ServerCertificateValidationCallback = (sender, certificate, chain, errors) =>
                                                      sslCertificatePermit ||
                                                      MailKit.MailService.DefaultServerCertificateValidationCallback(sender, certificate, chain, errors),
                Timeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds
            })
            {
                client.Connect(config.Host, config.Port,
                               config.EnableSSL ? SecureSocketOptions.Auto : SecureSocketOptions.None);

                if (config.EnableAuth)
                {
                    client.Authenticate(config.CredentialsUserName,
                                        config.CredentialsUserPassword);
                }

                client.Send(FormatOptions.Default, mimeMessage, CancellationToken.None);
            }
        }
Example #32
0
 public MailService(SmtpSettingsModel smtpSettingsModel, ILogger logger) : this(logger)
 {
     this.smtpSettingsModel = smtpSettingsModel;
 }
Example #33
0
        public void SendEmailAsync(MailMessageModel mailMessageModel, SmtpSettingsModel smtpSettingsModel = null)
        {
            var data = GetData(mailMessageModel, smtpSettingsModel);

            SendEmailAsync(data.Item1, data.Item2);
        }
Example #34
0
 public Messager(IOptions <SmtpSettingsModel> smtpSettings)
 {
     _smtpSettings = smtpSettings.Value;
 }