示例#1
0
        public BodyBuilder CreateBody(WebContact webContact)
        {
            string pathToFile = Path.Combine(
                Environment.CurrentDirectory,
                "Templates",
                webContact.EmailTemplate + ".html"
                );

            var builder = new BodyBuilder();

            using (StreamReader SourceReader = File.OpenText(pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            builder.HtmlBody = builder.HtmlBody.Replace("{webContact.Name}", webContact.Name);
            builder.HtmlBody = builder.HtmlBody.Replace("{webContact.Email}", webContact.Email);
            builder.HtmlBody = builder.HtmlBody.Replace("{webContact.Message}", webContact.Message);
            builder.HtmlBody = builder.HtmlBody.Replace("{webContact.SingleDetails.Ip}", webContact.SingleDetails.Ip);
            builder.HtmlBody = builder.HtmlBody.Replace("{webContact.SingleDetails.City}", webContact.SingleDetails.City);
            builder.HtmlBody = builder.HtmlBody.Replace("{webContact.SingleDetails.CountryName}", webContact.SingleDetails.CountryName);

            builder.TextBody =
                "&nbsp;&nbsp;&nbsp;&nbsp;Imię : <strong>" + webContact.Name + "</strong><br>" +
                "&nbsp;&nbsp;&nbsp;Email : " + webContact.Email + "<br>" +
                "&nbsp;&nbsp;&nbsp;Treść : " + webContact.Message + "<br><br>" +
                "Adres IP : <strong style=\"color:red\">" + webContact.SingleDetails.Ip + "</strong><br>" +
                "&nbsp;&nbsp;&nbsp;&nbsp;Kraj :" + webContact.SingleDetails.CountryName;

            return(builder);
        }
示例#2
0
        public async Task <IActionResult> Post([FromBody] WebContact webContact)
        {
            var ip = HttpContext.Connection.RemoteIpAddress.ToString();

            IpStackClient client = new IpStackClient(_ipStackOptions.Key);

            webContact.SingleDetails = client.GetIpAddressDetails(ip);
            webContact.EmailTemplate = _emailOptions.Template;

            MailRequest request = new MailRequest
            {
                ToEmail = _emailOptions.ToAddress,
                Subject = _emailOptions.Subject,
                Body    = _emailService.CreateBody(webContact)
            };

            await _emailService.SendAsync(request);

            await _emailService.SendGridAsync(request);

            //https://www.pragimtech.com/blog/blazor/post-in-aspnet-core-rest-api/

            return(StatusCode(StatusCodes.Status200OK, "Success"));
        }