Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

MailKit HTML format question

$
0
0

Hello,

I am getting Textarea value with jquery and pass it to action in order to send an e-mail. The problem is when it gets to the action, the markup gets lost. How can I keep the value with the markup and send an e-mail?

Here is the portion I am getting value from (result)

<div class="col-md-5"><div class="form-group container-fluid"><textarea class="form-control" id="result" rows="5" readonly></textarea></div><div class="form-group row container-fluid"><div class="col"><input id="btn_purchase" type="button" value="Purchase" class="btn btn-success" /></div><div class="col"> <input id="total" type="text" class="form-control w-25 float-right" readonly /></div></div></div>

Here is the jquery

$("#btn_purchase").click(function() {
        var result = $("#result").html();
        var total = $("#total").val();
        var email = $("#email").val();
        alert(result);
        var serviceURL = '/GameBanks/Send?body=' + result + '&total=' + total + '&email=' + email;$.ajax({
            type: "GET",
            url: serviceURL,
            dataType: 'json',
            success: function (data) {
                if(true)
                    alert("Email sent to " + email);
                else
                    alert("Email did not send to " + email);
            }
        });
    });

Here is the action:

 [HttpGet]
        public Boolean Send(string body, string total, string email)
        {
            var mailstatus = SendEmail(body, email);

            if (!mailstatus) return false;

            return true;
        }

public bool SendEmail(string message, string email)
        {
            try
            {
                                
                var messagem = new MimeMessage();
                messagem.From.Add(new MailboxAddress("gaming", "test@test.com"));
                messagem.To.Add(new MailboxAddress("Customer", email));
                messagem.Subject = "Serial";
                var builder = new BodyBuilder();
                builder.HtmlBody = message;
                messagem.Body = builder.ToMessageBody();

              
                using (var client = new MailKit.Net.Smtp.SmtpClient())
                {

                    client.Connect("smtp.yandex.com.tr", 587, false);

                    //SMTP server authentication if needed
                    client.Authenticate("test@test.com", "test");

                    client.Send(messagem);

                    client.Disconnect(true);

                    return true;
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }

        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>