public ActionResult UpdateEmailSetting(EmailSetting model) { try { if (ModelState.IsValid) { Configuration config = WebConfigurationManager.OpenWebConfiguration("~/"); MailSettingsSectionGroup mailSettings = config.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup; if (model != null) { mailSettings.Smtp.From = model.FromEmail; mailSettings.Smtp.Network.Password = model.Password; mailSettings.Smtp.Network.UserName = model.Username; mailSettings.Smtp.Network.Host = model.SMTPHost; mailSettings.Smtp.Network.Port = model.SMTPPort; config.Save(); ViewBag.Message = "Successfully saved."; } } return(View("EmailSetting", model)); } catch (Exception ex) { throw ex; } }
//Email, Local Folder, AWS S3 private void LoadOtherSettings() { try { AWSS3Helper awsHelper = new AWSS3Helper(); AWSS3 = awsHelper.GetConfig(); if (AWSS3 == null) { AWSS3 = new AWSS3Setting(); } EmailHelper emailHelper = new EmailHelper(); Email = emailHelper.GetConfig(); if (Email == null) { Email = new EmailSetting(); } GeneralSettingHelper generalHelper = new GeneralSettingHelper(); General = generalHelper.GetConfig(); if (General == null) { General = new GeneralSetting(); } } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while loading settings. \n" + message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
protected void btnAction_Command(object sender, CommandEventArgs e) { if (e.CommandName == "Save") { if (Page.IsValid) { EmailSetting item = new EmailSetting(); item.EmailId = emailId; item.Title = CommonHelper.fixquotesAccents(txtName.Text); item.Subject = CommonHelper.fixquotesAccents(txtSubject.Text); item.FromAddress = CommonHelper.fixquotesAccents(txtfromAddress.Text); item.ToAddress = CommonHelper.fixquotesAccents(txtToAddress.Text); item.Body = CommonHelper.fixquotesAccents(EmailBodyDesc.Content); EmailManager.SaveEmail(item); } lblSuccess.Visible = true; lblCancel.Visible = false; } else { Response.Redirect("EmailList.aspx"); } //Response.Redirect("EmailList.aspx"); }
public EmailSetting UpdateEmailSetting(EmailSetting updatedEmailSetting) { var entity = _context.EmailSettings.Attach(updatedEmailSetting); entity.State = EntityState.Modified; return(updatedEmailSetting); }
public void Save(EmailSetting Emailsetting) { if (Emailsetting.Id == 0) { context.EmailSettings.Add(Emailsetting); context.SaveChanges(); } else { EmailSetting dbEntry = context.EmailSettings.Find(Emailsetting.Id); if (dbEntry != null) { dbEntry.Id = Emailsetting.Id; dbEntry.SMTP_Server = Emailsetting.SMTP_Server; dbEntry.Sender = Emailsetting.Sender; dbEntry.SMTPServer_Port = Emailsetting.SMTPServer_Port; dbEntry.UserName = Emailsetting.UserName; dbEntry.Password = Emailsetting.Password; dbEntry.EnableSSL = Emailsetting.EnableSSL; dbEntry.Last_Update = Emailsetting.Last_Update; dbEntry.UserId = Emailsetting.UserId; context.SaveChanges(); } } }
//Email Sender public void EMailPasswordSender(string receiver, string Password) { EmailSetting _emailsetting = repositoryEmailSetting.GetEmailSetting; MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(_emailsetting.SMTP_Server); mail.From = new MailAddress(_emailsetting.Sender); mail.To.Add(receiver); mail.Subject = "Your Password"; string HashUserPassword = repositoryDEncryption.Decrypt(Password); mail.Body = HashUserPassword; // SmtpServer.Port = _emailsetting.SMTPServer_Port; string HashEmailPassword = repositoryDEncryption.Decrypt(_emailsetting.Password); SmtpServer.Credentials = new NetworkCredential(_emailsetting.UserName, HashEmailPassword); NetworkCredential Credentials = new NetworkCredential(_emailsetting.Sender, HashEmailPassword); SmtpServer.Credentials = Credentials; // SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; // SmtpServer.UseDefaultCredentials = true; // SmtpServer.EnableSsl = _emailsetting.EnableSSL; SmtpServer.Send(mail); }
public IActionResult SaveEmailSettings([FromBody] EmailSettingModel model) { if (ModelState.IsValid) { EmailSetting entity = new EmailSetting(); model.CopyTo(entity); int i = 0; List <EmailBody> bodies = new List <EmailBody>(); foreach (var item in model.Name) { if (item.IsNotEmpty() && model.Content[i].IsNotEmpty()) { bodies.Add(new EmailBody() { Name = item, Content = model.Content[i] }); } i++; } entity.Bodies = bodies; return(_settingService.Save(entity).SaveResult(T)); } return(SaveFailure(GetModelErrors())); }
public void Post([FromBody] EmailSetting emailSetting) { if (ModelState.IsValid) { EmailSettingRepository.Add(emailSetting); } }
public async Task <IHttpActionResult> SaveAbuse(AbuseViewModel model) { string userName = User.Identity.GetUserName(); ApplicationUser u = await GetApplicationUser(userName); var setting = _UnitOfWork.SettingRepository.GetSetting(); EmailSetting emailSettings = _UnitOfWork.EmailSetting.GetEmailSetting(EmailType.AbuseEmail.GetHashCode().ToString()); //Title //emailSettings.SubjectAr var messageBody = emailSettings.MessageBodyAr.Replace("@title", emailSettings.SubjectAr); messageBody = messageBody.Replace("@userName", userName); messageBody = messageBody.Replace("@subject", model.Title); messageBody = messageBody.Replace("@body", model.Message); EmailManager.SendAEmail(emailSettings.Host, emailSettings.Port, emailSettings.FromEmail, emailSettings.Password, setting.ContactUsEmail, messageBody, $"بلاغ إساءة من المستخدم {userName} "); model.UserId = u.Id; var abuse = Mapper.Map <AbuseViewModel, Abuse>(model); var result = _UnitOfWork.AbuseRepository.Create(abuse); _UnitOfWork.Commit(); return(Ok(result)); }
public void InstallServices(IServiceCollection services, IConfiguration configuration) { //Set the AppSettings information var appSettingValues = new AppSettings(); var emailSettingValues = new EmailSetting(); configuration.GetSection(nameof(AppSettings)).Bind(appSettingValues); configuration.GetSection(nameof(EmailSetting)).Bind(emailSettingValues); services.AddSingleton <AppSettings>(appSettingValues); services.AddSingleton <EmailSetting>(emailSettingValues); var authorizerSetting = new AuthorizerSetting(); configuration.GetSection("Authorizer").Bind(authorizerSetting); if (!services.Any(x => x.ServiceType == typeof(AuthorizerSetting))) { services.AddSingleton(authorizerSetting); } //Handlers and Resources services.AddSingleton <IMessagesResourceHandler, MessagesResourceHandler>(); services.AddSingleton <IMessageHandler, MessageHandler>(); // Add application services. services.AddTransient <ISMTPEmailSender, SMTPEmailSender>(); services.AddTransient <IRequestProvider, RequestProvider>(); //User Profile services.AddScoped <IUserProfile, UserProfile>(); }
private void AddBindings() { Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products).Returns(new List <Product> { new Product { Name = "Football", Price = 23 }, new Product { Name = "Caram board", Price = 293 }, new Product { Name = "Running Shoes", Price = 20 } }); // kernel.Bind<IProductRepository>().ToConstant(mock.Object); kernel.Bind <IProductRepository>().To <EFProductRepository>(); EmailSetting emailSetting = new EmailSetting { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind <IorderProcessor>().To <EmailOrderProcessor>().WithConstructorArgument("setting", emailSetting); }
/// <summary> /// Default constructor /// </summary> /// <param name="emailSettings"></param> /// <param name="logger"></param> public NotificationService( IOptions <EmailSetting> emailSettings, ILogger <NotificationService> logger) { this.emailSetting = emailSettings.Value; this.logger = logger; }
public AuthMessageSender( IOptions <EmailSetting> emailSettings, IHostingEnvironment env) { _emailSettings = emailSettings.Value; _env = env; }
public ActionResult SendEmail(FormCollection form) { string managerID = form["manager"].ToString(); int year = Convert.ToInt32(form["year"].ToString()); int period = Convert.ToInt32(form["period"].ToString()); var formModel = (from f in timesheetDb.TimeRecordForms where f.Year == year where f.Period == period where f.UserID == User.Identity.Name select f).FirstOrDefault(); if (formModel == null) { return(RedirectToAction("Index", new { message = 1 })); } else { formModel.ManagerIDs = managerID; formModel.status = _status.submited; formModel.SubmittedTime = DateTime.Now; timesheetDb.TimeRecordForms.Attach(formModel); timesheetDb.Entry(formModel).State = EntityState.Modified; timesheetDb.SaveChanges(); //do not wait for the async task to complete Task.Run(() => EmailSetting.SendEmail(managerID, string.Empty, "TimesheetApplication", formModel.TimeRecordFormId.ToString())); return(RedirectToAction("Index", new { message = 2 })); } }
/// <summary> /// Send the email directly /// </summary> /// <param name="emailAccount"></param> /// <param name="emailModel"></param> /// <returns></returns> public ResponseModel SendEmailDirectly(EmailAccount emailAccount, EmailModel emailModel) { var mailSetting = new EmailSetting { Host = emailAccount.Host, Port = emailAccount.Port, Timeout = emailAccount.TimeOut, EnableSsl = emailAccount.EnableSsl, User = emailAccount.Username, Password = emailAccount.Password }; var mailUtilities = new MailUtilities(mailSetting); try { mailUtilities.SendEmail(emailModel); return(new ResponseModel { Success = true, Message = T("EmailAccount_Message_SendEmailDirectlySuccessfully") }); } catch (Exception exception) { return(new ResponseModel { Success = false, Message = T("EmailAccount_Message_SendEmailDirectlyFailure"), DetailMessage = exception.Message }); } }
public static bool SendEmailToAdmins(int orderId) { //pull Specific Email Template int emailId = ConfigHelper.EmailAppSetting("AdminAlertEmailId"); EmailSetting emailTemplate = EmailManager.GetEmail(emailId); if (emailTemplate.Body != null) { //Body Translation String BodyTemplate = emailTemplate.Body.Replace("&", "&"); BodyTemplate = BodyTemplate.Replace("{OrderId}", orderId.ToString()); BodyTemplate = BodyTemplate.Replace("&", "&"); try { //Prepare Mail Message MailMessage _oMailMessage = new MailMessage(emailTemplate.FromAddress, emailTemplate.ToAddress, emailTemplate.Subject, BodyTemplate); _oMailMessage.IsBodyHtml = true; SendMail(_oMailMessage); return(true); } catch (Exception) { return(false); } } else { return(false); } }
public SaleService(ApplicationDbContext context, IOptions <EmailSetting> options, IOrderService order, IOptions <InternalConfiguration> internalOptions) { _context = context; _settings = options.Value; _order = order; _internalOptions = internalOptions.Value; }
protected SmtpEmailClient(EmailSetting emailSettings) { _smtpClient = new SmtpClient(emailSettings.Host, emailSettings.Port) { Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password), EnableSsl = true }; }
public NotificationRepository( ILogger <NotificationRepository> logger, IOptions <EmailSetting> emailSettings) { _logger = logger; _emailSettings = emailSettings.Value; _logger.LogInformation("NotificationRepository Initiated"); }
public void Put(int id, [FromBody] EmailSetting emailSetting) { emailSetting.Id = id; if (ModelState.IsValid) { EmailSettingRepository.Update(emailSetting); } }
private EmailSetting GetEmailSettingSession() { if (Session["Emailsetting"] == null) { Session["Emailsetting"] = new EmailSetting(); } return((EmailSetting)Session["Emailsetting"]); }
//This Action Should Run once only Install time ........******////// public ActionResult CreateEMailSetting() { EmailSetting model = new EmailSetting(); model.Id = 0; model.Last_Update = DateTime.Now.Date; return(View("UpdateEMailSetting", model)); }
private EmailSetting GetEmailMessage(string toName, string code, string messageTemplate) { EmailSetting emailSettings = _unitOfWork.EmailSetting.GetEmailSetting(messageTemplate); emailSettings.MessageBodyAr = emailSettings.MessageBodyAr.Replace("@FullName", toName); emailSettings.MessageBodyAr = emailSettings.MessageBodyAr.Replace("@code", "Code=" + code); return(emailSettings); }
public Commons(ApplicationDbContext context, IOptions <EmailSetting> options, UserManager <ApplicationUser> userManager, IOptions <InternalConfiguration> internalConfigurations) { _context = context; _settings = options.Value; _userManager = userManager; _internalOptions = internalConfigurations.Value; }
private void AddBindings(IContainer container) { EmailSetting emailSettings = new EmailSetting { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; container.Inject <EmailSetting>(emailSettings); }
public async Task <bool> ReSendSmsConfirmation(string url, ApplicationUser user) { var code = await GenerateToken(user.Id, EmailType.EmailConfirmation); EmailSetting emailSettings = _unitOfWork.EmailSetting.GetEmailSetting(EmailType.EmailConfirmation.GetHashCode().ToString()); EmailManager email = new EmailManager(); string message = emailSettings.MessageBodyAr.Replace("@code", user.UserName); return(email.SendSMS(url, user.PhoneNumber, message)); }
public void Add(EmailSetting emailSetting) { using (IDbConnection dbConnection = Connection) { string sQuery = "insert into EmailSetting(ServerName, SMTPAddress, Username, Password, Port, TLS_SSL_Required, IsDefault, IsActive)" + " VALUES (@ServerName,@SMTPAddress,@UserName,@Password,@Port,@TLS_SSL_Required,@IsDefault,@IsActive)"; dbConnection.Open(); dbConnection.Query(sQuery, emailSetting); } }
private void AddBinding() { EmailSetting em_set = new EmailSetting { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; KK.Bind <IRepository>().To <RepositoryForProduct>(); KK.Bind <IOrderToProduct>().To <OrderProccessorEmail>().WithConstructorArgument("Em", em_set); }
protected void LoadEmalTemplate(int emailId) { EmailSetting emailItem = EmailManager.GetEmail(emailId); txtName.Text = emailItem.Title; txtfromAddress.Text = emailItem.FromAddress; txtToAddress.Text = emailItem.ToAddress; txtSubject.Text = emailItem.Subject; EmailBodyDesc.Content = emailItem.Body; }
private async Task <bool> SendPasswordResetToken(string smsUrl, ApplicationUser user) { var code = await GenerateToken(user.Id, EmailType.ForgetPassword); EmailSetting emailSettings = _unitOfWork.EmailSetting.GetEmailSetting(EmailType.ForgetPassword.GetHashCode().ToString()); EmailManager email = new EmailManager(); string message = emailSettings.MessageBodyAr.Replace("@code", code); //message = message.Replace("@code", code); return(email.SendSMS(smsUrl, user.PhoneNumber, message)); }
public async Task<bool> SaveEmail(EmailSetting email) { await this.LoadOptions(Sections.Button.EmailSettings); // post the data to the info NameValueCollection nvc = new NameValueCollection(); nvc.Add(email.WebFormData); nvc.Add(FormInputNames.EmailSettings.UpdateButton, FormInputNames.EmailSettings.UpdateButtonValue); var doc = await MyApi.CallApi("TextEmailSettings.aspx", true, nvc); try { PayByPhoneApi.VerifyMessage(doc); } catch (UnexpectedResponseException ex) { Console.WriteLine(ex); return false; } return true; }
public ActionResult Index(EmailSetting setting) { if (ModelState.IsValid) { setting.Password = Encrypt(setting.Password); db.Entry(setting).State = EntityState.Modified; db.SaveChanges(); return Redirect("~/Message"); } return View(setting); }
public ActionResult EmailSetting(EmailSetting m) { bool result = true; var req = YunClient.Instance.Execute(new SetEmailSettingRequest { From = m.From, Password = m.Password, Port = m.Port, Server = m.Server, Ssl = m.Ssl ? 1 : 0, UserName = m.UserName }, Member.Token); result = req.IsError; if (result) { ModelState.AddModelError("SaveError", "操作失败"); return View(m); } else { ModelState.AddModelError("SaveError", "操作成功"); return RedirectToAction("EmailSetting"); } }