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 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); }
public PapercutSmtpService() { SmtpSettings = new SmtpSettingsModel(); SmtpSettings.HostUrl = "localhost"; SmtpSettings.Port = 25; SmtpSettings.EnableSsl = false; SmtpSettings.FromAddress = "*****@*****.**"; }
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)); }
public OutlookSmptService() { SmtpSettings = new SmtpSettingsModel(); SmtpSettings.FromAddress = "*****@*****.**"; SmtpSettings.HostUrl = "smtp.office365.com"; SmtpSettings.Port = 587; SmtpSettings.EnableSsl = true; SmtpSettings.ApiKeyOrPassword = ""; }
public GmailSmptService() { SmtpSettings = new SmtpSettingsModel(); SmtpSettings.HostUrl = "smtp.gmail.com"; SmtpSettings.Port = 587; SmtpSettings.EnableSsl = true; SmtpSettings.ApiKeyOrPassword = ""; SmtpSettings.FromAddress = "*****@*****.**"; }
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)); }
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)); }
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); } }
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)); }
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); }
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); }
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)); } }
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; }
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)); }
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)); }
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)); }
protected SmtpClient GetSmtpClient(SmtpSettingsModel smtpSettingsModel) { PrepareSending(ref smtpSettingsModel); return(smtpSettingsModel.GetSmtpClient()); }
public void SendEmailAsync(MailMessage message, SmtpSettingsModel smtpSettingsModel = null) { var client = GetSmtpClient(smtpSettingsModel); SendEmailAsync(message, client); }
public Task SendEmailAsyncTask(MailMessageModel mailMessageModel, SmtpSettingsModel smtpSettingsModel = null) { var data = GetData(mailMessageModel, smtpSettingsModel); return(SendEmailAsyncTask(data.Item1, data.Item2)); }
public Task SendEmailAsyncTask(MailMessage message, SmtpSettingsModel smtpSettingsModel = null) { var client = GetSmtpClient(smtpSettingsModel); return(SendEmailAsyncTask(message, client)); }
public MailServiceAsync(SmtpSettingsModel smtpSettingsModel, ILogger logger) : base(smtpSettingsModel, logger) { }
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); } }
public MailService(SmtpSettingsModel smtpSettingsModel, ILogger logger) : this(logger) { this.smtpSettingsModel = smtpSettingsModel; }
public void SendEmailAsync(MailMessageModel mailMessageModel, SmtpSettingsModel smtpSettingsModel = null) { var data = GetData(mailMessageModel, smtpSettingsModel); SendEmailAsync(data.Item1, data.Item2); }
public Messager(IOptions <SmtpSettingsModel> smtpSettings) { _smtpSettings = smtpSettings.Value; }