private void AddBindings() { kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile" ?? "false"]) }; kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); }
public void Can_Send_Email() { // Arrange - create and populate a cart Cart cart = new Cart(); cart.AddItem(new Product { ProductID = 1, Name = "Banana", Price = 10M }, 2); cart.AddItem(new Product { ProductID = 2, Name = "Apple", Price = 5M }, 2); // Arrange - create and populate some shipping details ShippingDetails shipDetails = new ShippingDetails { Name = "Joe Smith", Line1 = "Apartment 4a", Line2 = "123 West Street", City = "Northtown", State = "GA", Country = "USA", Zip = "12345" }; // Arrange - create the test-specific email settings EmailSettings settings = new EmailSettings { // put test specific settings here WriteAsFile = true }; // Arrange - create the EmailOrderProcessor class EmailOrderProcessor proc = new EmailOrderProcessor(settings); // Act - process the order proc.ProcessOrder(cart, shipDetails); // NOTE - there is assert in this test }
private void AddBindings() { // add bindings here _kernel.Bind<IProductRepository>().To<EfProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; // pass the webconfig value to the constructor of the emailorderprocessor _kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); // when using IAuthProvider, call my custom authentication provider for forms _kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); // mock repo //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns( // new List<Product> // { // new Product{Name = "Football", Price = 25}, // new Product{Name = "Surf board", Price = 179}, // new Product{Name = "Running shoes", Price = 95} // }); // want Ninject to return the same mock object whenever it gets a request - a singleton (using .ToConstant()) // _kernel.Bind<IProductRepository>().ToConstant(mock.Object); }
private void AddBingings() { #region mock_object //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> { // new Product { Name = "Football", Price = 25 }, // new Product { Name = "Surf board", Price = 179 }, // new Product { Name = "Running shoes", Price = 95 } //}.AsQueryable()); //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); #endregion //EF ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); //EMAIL EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager .AppSettings["Email.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>() .To<EmailOrderProcessor>() .WithConstructorArgument("settings", emailSettings); //AUTH ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
public void SendEmail(EmailSettings settings, string subject, string body, bool htmlBody = false) { var email = new MailMessage(); email.From = new MailAddress(settings.From); email.To.Add(settings.To); email.Subject = subject; email.Body = body; email.IsBodyHtml = htmlBody; NetworkCredential credentials = null; if (!string.IsNullOrWhiteSpace(settings.Username)) credentials = new NetworkCredential(settings.Username, settings.Password); try { Send(email, settings.Server, settings.Port, settings.Ssl, credentials); } catch(Exception ex) { _logger.Error("Error sending email. Subject: {0}", email.Subject); _logger.Debug(ex, ex.Message); throw; } }
private void AddBindings() { ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings(); ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { // put additional bindings here var prods = new Product[] { new Product{ProductID =1, Name ="Mangos", Category="Fruit", Description="Summer gift", Price=12M}, new Product{ProductID =2, Name ="Apples", Category="Fruit", Description="spring gift", Price=20M}, new Product{ProductID =3, Name ="Nike Joggers", Category="Sports", Description="football fever", Price=13M}, new Product{ProductID =4, Name ="Calculator", Category="Accounting", Description="japaniiii", Price=52M}, new Product{ProductID =5, Name ="PC", Category="Computers", Description="I am PC", Price=92M}, new Product{ProductID =6, Name ="MAC", Category="Computers", Description="I am Mac", Price=120M} }; //Mocking IProduct and setting what will its Products property will return Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(prods.AsQueryable()); //Registering the Mock object with IProductRepository //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>() .To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { // put bindings here //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> //{ // new Product {Name = "Football", Price = 25}, // new Product {Name = "Surf board", Price = 179}, // new Product {Name = "Running shoes", Price = 95} //}); //kernel.Bind<IProductRepository>().ToConstant(mock.Object); kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>() .WithConstructorArgument("settings", emailSettings); kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
public EmailNotifier(EmailSettings settings) { Settings = settings; // test settings if (settings.ToFunction == null || settings.From == null || settings.Host == null || settings.SubjectFunction == null || settings.BodyFunction == null) throw new Exception("Please at least fill in the following settings: Host, From, ToFunction, SubjectFunction, BodyFunction"); new SmtpClient(settings.Host, settings.Port ?? 25); }
private void AddBindings() { ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings() { WriteAsFile = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["EMail.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>().To<EMailOrderProcessor>().WithConstructorArgument("settings", emailSettings); ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
public void AddBindings() { kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind<IOrderProcessor>().To<InternetEmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { // Mock implementation of the IProductRepository ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); // EmailSettings emailSettings = new EmailSettings(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); container.RegisterType<IProductRepository, SportsStore.Domain.Concrete.EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager .AppSettings["Email.WriteAsFile"] ?? "false") }; container.RegisterType<IOrderProcessor, SportsStore.Domain.Concrete.EmailOrderProcessor>(new InjectionConstructor(emailSettings)); }
private void AddBindings() { kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false")//read the property }; kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>() .WithConstructorArgument("settings", emailSettings);//create an EmailSettings object to intect into the EmailOrderProcessor Constructor kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { // Здесь размещаются привязки Ninject kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings() { WriteAsFile = bool.Parse(ConfigurationManager .AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>() .WithConstructorArgument("settings",emailSettings); kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
public ValidationFailure Test(EmailSettings settings) { const string body = "Success! You have properly configured your email notification settings"; try { SendEmail(settings, "Sonarr - Test Notification", body); } catch (Exception ex) { _logger.Error(ex, "Unable to send test email: " + ex.Message); return new ValidationFailure("Server", "Unable to send test email"); } return null; }
//the bindings are where we put our actual DI bindings for use by the app private void AddBindings() { //this binding is for our EF repository //of course with dependency injection we are free to change our method of persistence //and all we need to do is change this line here ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager .AppSettings["Email.WriteAsFile"] ?? "false") }; //we bind our emailorderprocessor to the order processing interface, we also use the constructorArgument to add the email settings object ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); //this is our binding for authorization using Forms Auth ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> //{ // new Product {Name = "Football", Price = 25}, // new Product {Name = "Football", Price = 25}, // new Product {Name = "Football", Price = 25} //}); kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings() { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); }
private void AddBindings() { // put additional bindings here kernel.Bind<IProductRepository>().To<EFProductRepository>(); kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); // create the email settings object EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse( ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind<IOrderProcessor>() .To<EmailOrderProcessor>() .WithConstructorArgument("settings", emailSettings); }
private void addBindings(IKernel kernelParam) { var mock = new Mock<IProductRepository>(); mock.Setup(x => x.Products).Returns(new List<Product> { new Product { Name = "Football", Price = 25}, new Product { Name = "Surf board", Price = 179}, new Product { Name = "Running shoes", Price = 95} }); kernelParam.Bind<IProductRepository>().To<EFProductRepository>(); var emailSettings = new EmailSettings() { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["WriteAsFile"] ?? "false") }; kernelParam.Bind<IOrderProcessor>().To<EmailOrderProcessor>() .WithConstructorArgument("emailSettings", emailSettings); kernelParam.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
protected void AddBindings() { ////创建模仿存储库 //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product>{ // new Product{Name="Football",Price=25}, // new Product{Name="Surf board",Price=179}, //new Product{Name="Running shoes",Price=95}}.AsQueryable()); //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); //创建实体库绑定 ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "False") // }; ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); }
private void AddBindings() { //put bindings here //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> // { // new Product{Name="Football", Price=25}, // new Product{Name="Surf board", Price=179}, // new Product{Name="Running shoes",Price=95} // }.AsQueryable()); //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { }; ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); ninjectKernel.Bind<IAuthProvider>().To<FormAuthProvider>(); }
private void AddBindings() { /* Mock implementation of the IProductRepository Interface Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new List<Product> { new Product { Name = "Football", Price = 25 }, new Product { Name = "Surf board", Price = 179 }, new Product { Name = "Running shoes", Price = 95 } }.AsQueryable());*/ ninjectKernel.Bind<IProductRepository>().To<EFProductReposistory>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>() .To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); }
public void OnImportsSatisfied_SettingsAreUpdated() { // Arrange. var eventAggregator = Mock.Create<IEventAggregator>(Behavior.Loose); var communicationService = Mock.Create<IConcurrencyCommunicationService>(Behavior.Loose); var utils = Mock.Create<IUtils>(Behavior.Loose); Mock.Arrange(() => utils.CurrentUserAuthenticated).Returns(true); var emailSettingsRetriever = Mock.Create<EmailSettingsRetriever>(Behavior.Loose); Mock.Arrange(() => emailSettingsRetriever.DetailsFromAddress).Returns("*****@*****.**"); Mock.Arrange(() => EmailSettingsRetriever.GetEmailSettingsAsync()).Returns(TaskHelper.FromResult(emailSettingsRetriever)); var settings = new EmailSettings(eventAggregator, communicationService, utils); // Act. settings.OnImportsSatisfied(); // Assert. Assert.IsTrue(settings.CanSendFromDetails); }
private void AddBindings() { //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> //{ // new Product{ Name = "Pilka nozna", Price = 25}, // new Product{ Name = "Deska surfingowa", Price = 179}, // new Product{ Name = "Buty do biegania", Price = 95} //}.AsQueryable()); //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); }
private void AddBindings() { /* Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new List<Product> { new Product { Name = "Football", Price = 25 }, new Product { Name = "Surf Board", Price = 179 }, new Product { Name = "Running Shoes", Price = 95 } }.AsQueryable()); ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); * */ ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "true") }; ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument("settings", emailSettings); ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { // конфигурирование контейнера //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> { // new Product { Name = "Football", Price = 25, Category="Watersports", ProductID=1 }, // new Product { Name = "Surf board", Price = 179, Category="Soccer", ProductID=2 }, // new Product { Name = "Running shoes", Price = 95, Category="Chess", ProductID=3 } //}.AsQueryable()); //ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object); ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager .AppSettings["Email.WriteAsFile"] ?? "false") }; ninjectKernel.Bind<IOrderProcessor>() .To<EmailOrderProcessor>() .WithConstructorArgument("settings", emailSettings); ninjectKernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
private void AddBindings() { //Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> { // new Product { Name = "Football", Price = 25 }, // new Product { Name = "Surf board", Price = 179 }, // new Product { Name = "Running shoes", Price = 95 } //}.AsQueryable()); //ninjectKernel.Bind<IProductsRepository>().ToConstant(mock.Object); ninjectKernel.Bind<IProductsRepository>().To<EFProductRepository>(); //put bindings here //绑定一个邮件发送接口 //创建一个邮件参数 EmailSettings emailSettings = new EmailSettings { WriteAsFile = bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; //"settings"是(EmailOrderProcessor构造函数形参名) ninjectKernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>() .WithConstructorArgument("settings", emailSettings); }
private void AddBindings() { //Mock<IProductRepository> mock = new Mock<IProductRepository>(); //mock.Setup(m => m.Products).Returns(new List<Product> { // new Product { Name = "Football", Price = 25 }, // new Product { Name = "Surf board", Price = 179 }, // new Product { Name = "Running shoes", Price = 95 } //}); //kernel.Bind<IProductRepository>().ToConstant(mock.Object); kernel.Bind<IProductRepository>().To<EFProductRepository>(); EmailSettings emailSettings = new EmailSettings { FileLocation = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/EmailStorage"), WriteAsFile = true //bool.Parse(ConfigurationManager.AppSettings["Email.WriteAsFile"] ?? "false") }; kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>() .WithConstructorArgument("emailSettings", emailSettings); kernel.Bind<IAuthProvider>().To<FormsAuthProvider>(); }
public async Task <ServiceResult> SendEmailAsync() { var app = new AppManager(Globals.DBConnectionKey, "web", ""); string secret = app.GetSetting("AppKey")?.Value; var gsecred = Globals.Application.AppSetting("AppKey"); if (gsecred != secret) { throw new NotImplementedException(); } var encemail = Cipher.Crypt(secret, "*****@*****.**".ToLower(), true); encemail = Cipher.Crypt(secret, "*****@*****.**".ToLower(), true); encemail = Cipher.Crypt(secret, "*****@*****.**".ToLower(), true); encemail = Cipher.Crypt(secret, "*****@*****.**".ToLower(), true); if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } EmailSettings settings = new EmailSettings(); settings.FromUserUUID = CurrentUser.UUID; try { string content = await Request.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(content)) { return(ServiceResponse.Error("You must send valid email info.")); } var message = JsonConvert.DeserializeObject <EmailMessage>(content); if (string.IsNullOrWhiteSpace(message.SendTo)) { return(ServiceResponse.Error("You must send a user id for the message.")); } if (string.IsNullOrWhiteSpace(message.Body)) { return(ServiceResponse.Error("You must send comment in the message.")); } UserManager userManager = new UserManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); switch (message.Type?.ToUpper()) { case "ACCOUNT": var am = new AccountManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); var res = am.Get(message.SendTo); if (res.Code != 200) { return(res); } // Account account = (Account)res.Result; break; case "SUPPORT": //todo call api/Site/SendMessage break; case "USER": var resUserTO = userManager.Get(message.SendTo); if (resUserTO == null || resUserTO.Code != 200) { return(ServiceResponse.Error("User not found for user uuid.")); } var userTO = (User)resUserTO.Result; // THIS SHOULD BE sand, EMAILLOG.userUUID should be this. if (message.SendTo != userTO.UUID) { return(ServiceResponse.Error("User id doesn't match the addressed user id.")); } //if (message.SendFrom != CurrentUser.UUID) // return ServiceResponse.Error("Current user doesn't match logged in user."); //may just set the from user = currentuser break; case "PROFILE": ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); var dbProfile = profileManager.Get(message.SendTo); if (dbProfile.Code != 200) { return(ServiceResponse.Error("Profile not found.")); } var node = userManager.Get(((Profile)dbProfile.Result).UserUUID); if (node.Code != 200) { return(node); } var user = (User)node.Result; settings.ToUserUUID = user.UUID; if (string.IsNullOrWhiteSpace(message.Subject)) { message.Subject = "You have received a message from " + CurrentUser.Name; } break; default: var res2 = userManager.GetUser(message.SendTo, false); if (res2.Code != 200) { return(res2); } var toUser = (User)res2.Result; if (toUser == null) { return(ServiceResponse.Error("User not found.")); } settings.ToUserUUID = toUser.UUID; break; } string hostPassword = Cipher.Crypt(Globals.Application.AppSetting("AppKey"), Globals.Application.AppSetting("EmailHostPassword"), false); settings.EncryptionKey = Globals.Application.AppSetting("AppKey"); settings.HostPassword = hostPassword;// Globals.Application.AppSetting("EmailHostPassword"); settings.HostUser = Globals.Application.AppSetting("EmailHostUser"); settings.MailHost = Globals.Application.AppSetting("MailHost"); settings.MailPort = StringEx.ConvertTo <int>(Globals.Application.AppSetting("MailPort")); settings.SiteDomain = Globals.Application.AppSetting("SiteDomain"); settings.EmailDomain = Globals.Application.AppSetting("EmailDomain"); settings.SiteEmail = Globals.Application.AppSetting("SiteEmail"); settings.UseSSL = StringEx.ConvertTo <bool>(Globals.Application.AppSetting("UseSSL")); message.IpAddress = network.GetClientIpAddress(this.Request); return(await userManager.SendEmailAsync(message, settings)); } catch (Exception ex) { Debug.Assert(false, ex.Message); return(ServiceResponse.Error("Failed to send message.", ex.DeserializeException())); } }
public EmailSender(InternalEmailSender inernalSender, IOptionsSnapshot <EmailSettings> emailSettings) { this.inernalSender = inernalSender; this.emailSettings = emailSettings?.Value; }
public ContactController(ILogger <ContactController> logger, DataContext dataContext, EmailSettings emailSettings) { _logger = logger; _dataContext = dataContext; _emailSettings = emailSettings; }
public FaultEmailWriter() { m_emailSettings = new EmailSettings(); m_faultEmailSettings = new FaultEmailSettings(); }
public async Task <ServiceResult> SendEmailAsync(string ip, string toEmail, string fromEmail, string subject, string body, EmailSettings settings) { if (string.IsNullOrWhiteSpace(settings.SiteDomain)) { _logger.InsertError("The email setting site domain key is not set.", "UserManager", "SendEmail"); return(ServiceResponse.Error("An error occured when sending the message. <br/>ERROR: Site Domain configuration.")); } if (string.IsNullOrWhiteSpace(settings.SiteEmail)) { _logger.InsertError("The email setting SiteEmail is not set.", "UserManager", "SendEmail"); return(ServiceResponse.Error("An error occured when sending the message.")); } string siteEmail = settings.SiteEmail; MailAddress ma = new MailAddress(siteEmail, settings.SiteDomain); MailMessage mail = new MailMessage(); mail.From = ma; mail.ReplyToList.Add(ma); mail.To.Add(toEmail); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; SMTP mailServer = new SMTP(this._connectionKey, settings); return(await mailServer.SendMailAsync(mail)); }
public SendGridEmailService(IOptions <EmailSettings> settings, ILogger <SendGridEmailService> logger) { this.settings = settings.Value; this.logger = logger; }
public EmailSender(IOptions <EmailSettings> emailSettings, IHostingEnvironment env) { _emailSettings = emailSettings.Value; _env = env; }
public UsersController(medicalcenterContext context, IOptions <EmailSettings> emailSettings) { _context = context; _emailSettings = emailSettings.Value; }
public async Task <IActionResult> UpdateEmailOptions(EmailSettings model) { OperationResult result = await _mediatr.Send(new UpdateConfigSectionCommand(model)); return(HandleResult(result)); }
public EmailService(EmailSettings emailSettings) { smtpClient = new SmtpClient(); this.emailSettings = emailSettings; smtpClient.Connect(emailSettings.MailServer, emailSettings.MailPort, true); }
public static async Task SendEmailAsync(EmailSettings emailSettings, EmailMessageType messageType, string title, string subject, string toEmail, string name = "Valued User", int titleFontSize = 30) { await SendEmail(emailSettings, subject, await BuildHtmlMessage(messageType, title), toEmail, name); }
public EmailService(IOptions <EmailSettings> emailSettings, IWebHostEnvironment env) { _emailSettings = emailSettings.Value; _env = env; }
public EmailSender(IOptions <EmailSettings> emailSettings) { _emailSettings = emailSettings.Value; }
public ForgotPasswordModel(UserManager <ApplicationUser> userManager, IEmailSender emailSender, IOptions <EmailSettings> options) { _userManager = userManager; _emailSender = emailSender; _settings = options.Value; }
public EmailHelper(EmailSettings _eSettings) { this._eSettings = _eSettings; }
public IdentityEmailSender(EmailSettings emailSettings, ILogger <IdentityEmailSender> logger) : base(emailSettings, logger) { }
private void SaveEmailSetting(EmailSettings setting, User user) { try { /*if (user == null || user.ID == 0) * { * throw new InvalidDatabaseStateException(UIFatalExceptionIdentifiers.CurrentUserIsNotValid, "کاربر جاری نا معتبر است", ExceptionSrc); * }*/ if (user.UserSetting == null || user.UserSetting.ID == 0) { user.UserSetting = this.GetUserSettings(user); } if (user.UserSetting.EmailSettings == null) { user.UserSetting.EmailSettings = this.GetEmailSettings(user.UserSetting); } UserSettings userSetting = base.GetByID(user.UserSetting.ID); userSetting.EmailSettings.Active = setting.Active; userSetting.EmailSettings.DayHour = Utility.RealTimeToIntTime(setting.TheDayHour); userSetting.EmailSettings.DayCount = setting.DayCount; userSetting.EmailSettings.Hour = Utility.RealTimeToIntTime(setting.TheHour); userSetting.EmailSettings.SendByDay = setting.SendByDay; #region validation UIValidationExceptions exceptions = new UIValidationExceptions(); if (setting.Active) { if (setting.SendByDay) { if (userSetting.EmailSettings.DayHour == 0) { exceptions.Add(new ValidationException(ExceptionResourceKeys.UserSet_EmailTimeIsNotValid, "زمان ارسال ایمیل نا معتبر است", ExceptionSrc)); } } else { if (userSetting.EmailSettings.Hour == 0) { exceptions.Add(new ValidationException(ExceptionResourceKeys.UserSet_EmailTimeIsNotValid, "زمان ارسال ایمیل نا معتبر است", ExceptionSrc)); } else if (userSetting.EmailSettings.Hour < 5) { exceptions.Add(new ValidationException(ExceptionResourceKeys.UserSet_EmailTimeLessThanMin, "تکرار زمان ارسال ایمیل حداقل 5 دقیقه میباشد", ExceptionSrc)); } } } if (exceptions.Count > 0) { throw exceptions; } #endregion this.SaveChanges(userSetting, UIActionType.EDIT); } catch (Exception ex) { LogException(ex, "BUserSettings", "SaveEmailSetting"); throw ex; } }
public EmailService(IOptions <EmailSettings> appSettings) { _appSettings = appSettings.Value; }
public Startup(IConfiguration configuration) { emailService = new EmailSettings(); Configuration = configuration; Configuration.GetSection("EmailSettings").Bind(emailService); }
//private readonly ILogger _logger; public EmailSender(IOptions <EmailSettings> emailSettings /*, ILogger logger*/) { _emailSettings = emailSettings.Value; //_logger = logger; }
public AuthMessageSender(IOptions <EmailSettings> emailSettings) { this.emailSettings = emailSettings.Value; }
public AuthMessageSender(IOptions <EmailSettings> emailOptions) { _emailSettings = emailOptions.Value; }
public Settings() { Email = new EmailSettings(); Phone = new PhoneSettings(); }
public async Task <ServiceResult> SendUserInfoAsync(User user, string ipAddress, EmailSettings settings) { if (string.IsNullOrWhiteSpace(settings.SiteDomain)) { return(ServiceResponse.Error("The applications site domain key is not set.")); } if (string.IsNullOrWhiteSpace(settings.SiteEmail)) { return(ServiceResponse.Error("The applications site email key is not set.")); } #region build email from template //users/validate/type/:type/operation/:operation/code/:code string validationUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/pwdr/code/" + user.ProviderUserKey; string oopsUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mdel/code/" + user.ProviderUserKey; // string validationUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=pwdr&code=" + user.ProviderUserKey; //string oopsUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mdel&code=" + user.ProviderUserKey; DocumentManager dm = new DocumentManager(this._connectionKey, SessionKey); ServiceResult docRes = dm.GetTemplate("UserInfoEmail"); if (docRes.Status != "OK") { return(docRes); } string template = docRes.Result?.ToString(); template = template.Replace("[DOMAIN]", settings.SiteDomain); template = template.Replace("[USERNAME]", user.Name); template = template.Replace("[UPDATEPASSWORD_LINK]", validationUrl); template = template.Replace("[UNREGISTRATION_LINK]", oopsUrl); #endregion MailAddress ma = new MailAddress(settings.SiteEmail, settings.SiteDomain); MailMessage mail = new MailMessage(); mail.From = ma; mail.ReplyToList.Add(ma); mail.To.Add(user.Email); mail.Subject = settings.SiteDomain + " Account Information"; mail.Body = template; mail.IsBodyHtml = true; SMTP mailServer = new SMTP(this._connectionKey, settings); return(await mailServer.SendMailAsync(mail)); }
public ServiceResult SendUserEmailValidation(User user, string validationCode, string ipAddress, EmailSettings settings) { if (string.IsNullOrWhiteSpace(settings.SiteDomain)) { return(ServiceResponse.Error("The applications site domain key is not set.")); } if (string.IsNullOrWhiteSpace(settings.SiteEmail)) { return(ServiceResponse.Error("The applications site email key is not set.")); } #region build email from template string validationUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mreg/code/" + validationCode; string oopsUrl = "http://" + settings.SiteDomain + "/membership/validate/type/mbr/operation/mdel/code/" + validationCode; // string validationUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mreg&code=" + validationCode; // string oopsUrl = "http://" + settings.SiteDomain + "/users/validate?type=mbr&operation=mdel&code=" + validationCode; DocumentManager dm = new DocumentManager(this._connectionKey, SessionKey); ServiceResult docRes = dm.GetTemplate("EmailNewMember"); if (docRes.Status != "OK") { return(docRes); } string template = docRes.Result?.ToString(); if (string.IsNullOrWhiteSpace(template)) { return(ServiceResponse.Error("Unable to locate email template.")); } template = template.Replace("[DOMAIN]", settings.SiteDomain); template = template.Replace("[USERNAME]", user.Name); template = template.Replace("[REGISTRATION_LINK]", validationUrl); template = template.Replace("[UNREGISTRATION_LINK]", oopsUrl); #endregion MailAddress ma = new MailAddress(settings.SiteEmail, settings.SiteDomain); MailMessage mail = new MailMessage(); mail.From = ma; mail.ReplyToList.Add(ma); mail.To.Add(user.Email); mail.Subject = settings.SiteDomain + " account registration."; mail.Body = template; mail.IsBodyHtml = true; SMTP mailServer = new SMTP(this._connectionKey, settings); return(mailServer.SendMail(mail)); }
public EmailSender(IOptions <EmailSettings> config) { _emailSettings = config.Value; }
public EmailOrderProcessor(EmailSettings settings) { emailSettings = settings; }
public EmailService(IOptions <EmailSettings> emailSettings) { _emailSettings = emailSettings.Value; }
public SendGridEmailSender(EmailSettings emailSettings) { _emailSettings = emailSettings; }
public static async Task SendEmailAsync(EmailSettings emailSettings, string messageHtml, string title, string subject, string toEmail, string name = "Valued User") { await SendEmail(emailSettings, subject, await BuildHtmlMessage(messageHtml, title), toEmail, name); }