public void GeneralSend() { SmtpConfig mailConfig = new SmtpConfig(); SendStatus status = MailSend.MailTo(mailConfig, new MailAddress("*****@*****.**", "王勤军", Encoding.Default), new MailAddress("*****@*****.**", "王勤军", Encoding.Default), null, null, "邮件测试", "邮件内容", true, null); if (!status.Success) { //提示发送邮件错误 } }
public PasswordChangedEventModelFactory(SmtpConfig smtpConfig, string templateFile) { this._smtpConfig = smtpConfig; this._templateFile = templateFile; }
public ResetLinkPasswordRecoveryMailModelFactory(SmtpConfig smtpConfig, string templateFile) { this._smtpConfig = smtpConfig; this._templateFile = templateFile; }
public IActionResult SmtpConfiguration(SmtpConfig smtpConfig) { Parameters.Save(smtpConfig, SmtpConfig.KEY_NAME, _context); //return View(smtpConfig); return(RedirectToAction(nameof(Index))); }
public MailController(IOptions <SmtpConfig> smtpConfig) { SmtpConfig = smtpConfig.Value; }
public static MailProvider GetMailprovider() { MailProvider mp = new MailProvider(); smtpConfig = (SmtpConfig)SmtpConfig.GetConfiguration(); return mp; }
public EmailService(SmtpConfig config) { _config = config; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowSpecificOrigins", builder => { builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Include; options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); services.AddDbContext <SmallRepairDbContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("SmallRepair")); }); var smtpConfig = new SmtpConfig(); Configuration.GetSection("Smtp").Bind(smtpConfig); services.AddTransient <RepositoryEntity, RepositoryEntity>(); services.AddTransient(s => new Email(smtpConfig)); services.AddTransient <CompanyBusiness, CompanyBusiness>(); services.AddTransient <AssessmentBusiness, AssessmentBusiness>(); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes("auth-webapi-authentication-valid")), ClockSkew = TimeSpan.FromMinutes(5), ValidIssuer = "AvisoFacil.Auth.WebApp", ValidAudience = "Auth", }; }); services.AddApiVersioning(o => { o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(2, 0); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v2.0", new OpenApiInfo { Title = "Small Repair", Version = "v2.0", Description = "Small Repair API", }); c.SchemaFilter <EnumSchemaFilter>(); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); }
public void SmtpConfigTest() { SmtpConfig mailConfig = new SmtpConfig().Protect(); }
public SmtpService(IOptions <SmtpConfig> smtpConfig, IEmailGenerator emailGenerator) { _smtpConfig = smtpConfig.Value; _emailGenerator = emailGenerator; }
public EmailService(IOptions <SmtpConfig> smtpConfig) { _smtpConfig = smtpConfig.Value; }
public DirectPassRecoveryMailModelFactory(SmtpConfig smtpConfig, string templateFile) { this._smtpConfig = smtpConfig; this._templateFile = templateFile; }
public HomeController(IOptions <ConnectionStringsConfig> connectionStringsConfig, IOptions <SmtpConfig> smtpConfig) { this.connectionStringsConfig = connectionStringsConfig.Value; this.smtpConfig = smtpConfig.Value; }
public SmtpEmailService(SmtpConfig smtpConfig) { _smtpConfig = smtpConfig; }
private async Task SendEmailAsync(MailboxAddress sender, MailboxAddress recepient, string subject, string body, SmtpConfig config = null, bool isHtml = true) { MimeMessage message = new MimeMessage(); message.From.Add(sender); message.To.Add(recepient); message.Subject = subject; message.Body = isHtml ? new BodyBuilder { HtmlBody = body }.ToMessageBody() : new TextPart("plain") { Text = body }; if (config == null) { config = _config; } using (SmtpClient client = new SmtpClient()) { if (!config.UseSSL) { client.ServerCertificateValidationCallback = (object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true; } await client.ConnectAsync(config.Host, config.Port, config.UseSSL).ConfigureAwait(false); client.AuthenticationMechanisms.Remove("XOAUTH2"); if (!string.IsNullOrWhiteSpace(config.Username)) { await client.AuthenticateAsync(config.Username, config.Password).ConfigureAwait(false); } await client.SendAsync(message).ConfigureAwait(false); await client.DisconnectAsync(true).ConfigureAwait(false); } }
public SmtpService(IOptions <SmtpConfig> config, ILogger <SmtpService> logger) { _config = config.Value; _logger = logger; }
public static IServiceCollection AddOpenIdAuthority(this IServiceCollection services, IConfiguration configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var idProviderConfig = new IdProviderConfig(); configuration.Bind("IdProvider", idProviderConfig); services.AddSingleton(idProviderConfig); var hostingConfig = new HostingConfig(); configuration.Bind("Hosting", hostingConfig); services.AddSingleton(hostingConfig); var clientConfigs = configuration.GetSection("Apps").Get <List <ClientAppConfig> >() ?? new List <ClientAppConfig>(); var clients = ClientConfigHelper.GetClientsFromConfig(clientConfigs); var apps = ClientConfigHelper.GetAppsFromClients(clients); var appStore = new InMemoryAppStore(apps); services.AddSingleton <IAppStore>(appStore); var idScopeConfig = configuration.GetSection("IdScopes").Get <List <IdScopeConfig> >() ?? new List <IdScopeConfig>(); var idScopes = idScopeConfig.Select(x => new IdentityResource(x.Name, x.DisplayName ?? x.Name, x.ClaimTypes) { Required = x.Required }).ToList(); idScopes.AddRange(new List <IdentityResource>() { new IdentityResources.OpenId(), new IdentityResources.Profile(), new IdentityResources.Email(), new IdentityResources.Phone(), new IdentityResources.Address(), }); var connection = configuration.GetConnectionString("OpenIdAuthority"); services.AddDbContext <OpenIdAuthorityDbContext>(options => options.UseSqlServer(connection)); services.AddTransient <IOneTimeCodeStore, DbOneTimeCodeStore>(); services.AddTransient <IOneTimeCodeService, OneTimeCodeService>(); services.AddTransient <IUserStore, DbUserStore>(); services.AddTransient <IMessageService, MessageService>(); services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "/signin"; options.UserInteraction.LogoutUrl = "/signout"; options.UserInteraction.LogoutIdParameter = "id"; options.UserInteraction.ErrorUrl = "/error"; options.Authentication.CookieLifetime = TimeSpan.FromMinutes(idProviderConfig.DefaultSessionLengthMinutes); }) .AddDeveloperSigningCredential() //todo: replace .AddInMemoryClients(clients) .AddProfileService <ProfileService>() .AddInMemoryIdentityResources(idScopes); var smtpConfig = new SmtpConfig(); configuration.Bind("Mail:Smtp", smtpConfig); services.AddSingleton(smtpConfig); services.AddTransient <IEmailService, SmtpEmailService>(); var emailTemplates = ProcessEmailTemplates.GetTemplatesFromMailConfig(configuration.GetSection("Mail")); services.AddSingleton(emailTemplates); services.AddTransient <IEmailTemplateService, EmailTemplateService>(); services.AddSingleton <IPasswordHashService>(new AspNetIdentityPasswordHashService(10000)); services.AddTransient <IPasswordHashStore, DbPasswordHashStore>(); services.AddTransient <IPasswordService, DefaultPasswordService>(); services.AddTransient <AuthenticateOrchestrator>(); services.AddTransient <UserOrchestrator>(); services.AddEmbeddedViews(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // IUrlHelper services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); services.AddScoped <IUrlHelper>(x => { var actionContext = x.GetRequiredService <IActionContextAccessor>().ActionContext; var factory = x.GetRequiredService <IUrlHelperFactory>(); return(factory.GetUrlHelper(actionContext)); }); var allowedOrigins = clients.SelectMany(x => x.AllowedCorsOrigins).Distinct().ToArray(); if (allowedOrigins.Length > 0) { services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder .WithOrigins(allowedOrigins) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); } services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSingleton <ITempDataProvider, CookieTempDataProvider>(); return(services); }
public SmtpService(SmtpConfig smtpConfig) { this.smtpConfig = smtpConfig; }
public AuthMessageSender(IOptions <SmtpConfig> smtpConfig, IHttpContextAccessor httpContextAccessor) { _smtpConfig = smtpConfig.Value; _httpContextAccessor = httpContextAccessor; }
public static SmtpConfig Create() { if (_smtpConfig == null) { _smtpConfig = new SmtpConfig(); } return _smtpConfig; }
public EmailGenerator(IOptions <SmtpConfig> smtpConfig) { _smtpConfig = smtpConfig.Value; }
public object Create(object parent, object configContext, XmlNode section) { IDictionary<string, SmtpConfig> dic = new Dictionary<string, SmtpConfig>(); foreach (XmlNode item in section) { SmtpConfig smtp = new SmtpConfig(); smtp.Smtp = item.Attributes["value"].Value; smtp.Port = ConvertWrap.ToInt(item.Attributes["port"].Value, 25); smtp.UserName = item.Attributes["username"].Value; smtp.PassWord = item.Attributes["password"].Value; smtp.DisplyName = item.Attributes["displyname"].Value; dic.Add(item.Attributes["name"].Value, smtp); } return dic; }
public EmailSender(SmtpConfig smtpConfig) { _syncConfig = smtpConfig; _smtpClient = new SmtpClient(); }
public void SmtpConfigTest() { SmtpConfig mailConfig = new SmtpConfig().Protect(); }
public UserClaimsChangedEventModelFactory(SmtpConfig smtpConfig, string templateFile) { this._smtpConfig = smtpConfig; this._templateFile = templateFile; }