本文整理汇总了C#中EmailSettings类的典型用法代码示例。如果您正苦于以下问题:C# EmailSettings类的具体用法?C# EmailSettings怎么用?C# EmailSettings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmailSettings类属于命名空间,在下文中一共展示了EmailSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBindings
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>();
}
示例2: AddBindings
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);
}
示例3: AddBindings
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);
}
示例4: AddBingings
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>();
}
示例5: AddBindings
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>();
}
示例6: SendEmail
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;
}
}
示例7: AddBindings
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>();
}
示例8: Can_Send_Email
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
}
示例9: EmailNotifier
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);
}
示例10: AddBindings
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>();
}
示例11: AddBindings
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>();
}
示例12: AddBindings
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);
}
示例13: AddBindings
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>();
}
示例14: RegisterTypes
/// <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));
}
示例15: AddBindings
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>();
}