Ejemplo n.º 1
0
        public void Configure(
            IRoleService rolesService,
            IMapper mapper,
            IApplicationBuilder app,
            IWebHostEnvironment env,
            IUserService userService,
            CrmContext dataContext,
            IServiceProvider serviceProvider,
            IConfiguration configuration)
        {
            dataContext.Database.Migrate();
            ApplicationDbInitializer.SeedRoles(rolesService);
            ApplicationDbInitializer.SeedUsers(userService);
            MailCredentialsHelper.CheckIfCredentialsExist(
                new MailCredentials(
                    new MailAddress(
                        Configuration["MailAddress"] ?? "*****@*****.**",
                        Configuration["MailDisplayName"] ?? "CRMS-Team"),
                    new System.Net.NetworkCredential(Configuration["MailUserName"] ?? "*****@*****.**",
                                                     Configuration["MailPassword"] ?? "password"),
                    int.Parse(Configuration["MailPort"] ?? "587"),
                    Configuration["MailHost"] ?? "smtp.a.com"));
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseOpenApi();
            app.UseSwaggerUi3();

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/health");
            });

            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }
            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "wwwroot";
            });
            new UserCheckThread(serviceProvider.CreateScope().ServiceProvider.GetService <IUserCheckDateService>(), serviceProvider.CreateScope().ServiceProvider.GetService <IContactCheckDateService>(), configuration).runScheduledService().Wait();
        }
Ejemplo n.º 2
0
        private async Task <bool> SendMailAsync(string subject, string body, string emailAddressRecipient, Stream attachment, string attachmentType)
        {
            if (!USE_TESTMODE)
            {
                var mailCredentials = MailCredentialsHelper.GetMailCredentials();
                try
                {
                    MailMessage msg = new MailMessage();
                    string[]    str = new string[] { emailAddressRecipient };
                    msg.IsBodyHtml = true;
                    //Empfänger hinzufügen
                    foreach (string empf in str)
                    {
                        msg.To.Add(new MailAddress(empf));
                    }
                    msg.From    = mailCredentials.MailAddress;
                    msg.Subject = subject;
                    msg.Body    = body;

                    if (attachment != null)
                    {
                        msg.Attachments.Add(new Attachment(attachment, attachmentType));
                    }

                    SmtpClient client = new SmtpClient();
                    client.UseDefaultCredentials = false;

                    client.Credentials = mailCredentials.NetworkCredential;

                    client.Port = mailCredentials.Port;

                    client.Host           = mailCredentials.Host;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.EnableSsl      = true;
                    await client.SendMailAsync(msg);

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }
            else
            {
                return(CreateMailFiles(body, emailAddressRecipient, attachment, attachmentType));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> SaveMailCredentials([FromBody] MailCredentialsSerializableDto data)
        {
            await Task.Run(() => MailCredentialsHelper.SaveMailCredentials(new MailCredentials(_mapper.Map <MailCredentialsSerializable>(data))));

            return(Ok());
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> GetEmailCredentials()
 {
     return(await Task.FromResult(Ok(_mapper.Map <MailCredentialsSerializableDto>(new MailCredentialsSerializable(MailCredentialsHelper.GetMailCredentials())))));
 }