コード例 #1
0
        public IActionResult SendContactMessage([FromBody] ContactDto contact)
        {
            var secret = _webConfiguration.RecaptchaSecret;

            contact.Subject = "Contact Form Submission";

            var captchaResponse = CaptchaHelper.GetCaptchaResponse(
                secret,
                contact?.ClientResponse,
                HttpContext.Connection.RemoteIpAddress.ToString());

            if (!captchaResponse.Success)
            {
                return(BadRequest());
            }

            var email = new SendGridTransactionalMessageDto
            {
                ApiKey      = _webConfiguration.SendGridApiKey,
                Recipients  = SendGridConstants.SendGrid_DevelopmentRecipientEmail,
                FromAddress = SendGridConstants.SendGrid_DevelopmentRecipientEmail,
                Subject     = "Gray Wolf Contact Form",
                HtmlMessage =
                    $@"Name: {contact.Name} <br/>
                    Phone: {contact.PhoneNumber} <br/>
                    Email: {contact.Email} <br/>
                    Type: {contact.HelpYou} <br/>
                    Message: {contact.Comments}"
            };

            var response = _sendGridService.SendSingleEmail(email);

            return(Ok());
        }