Exemplo n.º 1
0
        public async Task <Response> Execute(string emailAddress)
        {
            var user = await _userService.FindByEmailAsync(emailAddress);

            if (user == null)
            {
                System.Net.HttpStatusCode statusCode = System.Net.HttpStatusCode.Unauthorized;
                return(new Response(statusCode, null, null));
            }

            var token  = _tokenHandler.CreatePasswordResetToken(user);
            var apiKey = Environment.GetEnvironmentVariable("Testology_sendgrid_key");
            var client = new SendGridClient(apiKey);
            var from   = new EmailAddress("*****@*****.**", "Ashley");
            // var from = new EmailAddress("*****@*****.**", "Ashley");
            var to             = new EmailAddress(emailAddress, "usuario de Testology");
            var templateData   = new MailData();
            var frontendDomain = _configuration.GetValue <string>("FrontendDomain");

            templateData.PasswordChangeUrl = frontendDomain + "/sesion/nuevo-pass/" + token;
            var msg      = MailHelper.CreateSingleTemplateEmail(from, to, "d-4bbc02bd9fd743bda97189fa9f4161f7", templateData);
            var response = await client.SendEmailAsync(msg);

            return(response);
        }