Guest User

Guest User

  • Tech Writer
  • 18
  • 2.9k

Send Email By Send Grid,

Mar 25 2021 11:46 AM
I have made a code using send gird api for send email.My email successfully send but i want to my email with proper format .
 
Please help me.
  1. var client = new SendGridClient(apiKey);  
  2. var msg = new SendGridMessage()  
  3. {  
  4. From = new EmailAddress("[email protected]"),  
  5. Subject = subject,  
  6. PlainTextContent = htmlContent,  
  7. HtmlContent = htmlContent  
  8. };  
  9. msg.AddTo(new EmailAddress(toEmail));  
  10. var response = await client.SendEmailAsync(msg); --this is my c# code  
this jquery and html code
  1. I have made a code using send gird api for send email.My email successfully send but i want to my email with proper format .  
  2. Please help me.  
  3. var client = new SendGridClient(apiKey);  
  4. var msg = new SendGridMessage()  
  5. {  
  6. From = new EmailAddress("[email protected]"),  
  7. Subject = subject,  
  8. PlainTextContent = htmlContent,  
  9. HtmlContent = htmlContent  
  10. };  
  11. msg.AddTo(new EmailAddress(toEmail));  
  12. var response = await client.SendEmailAsync(msg); --this is my c# code  
  13.    
  14. this jquery and html code  
  15. <div class="contact-main">  
  16. <div class="container">  
  17. <div class="row">  
  18. <div class="col-md">  
  19. <div class="back-shadow-contact ">  
  20. <h2>Get in Touch</h2>  
  21.    
  22. <form id="form">  
  23. <div class="form-row">  
  24. <div class="form-group col-md-6">  
  25. <input type="email" class="form-control form-contact" id="htmlContent" placeholder="Your Name" required="required"/>  
  26. </div>  
  27. <div class="form-group col-md-6">  
  28. <input type="text" class="form-control form-contact" id="toEmail" placeholder="Your Email Address" required />  
  29. </div>  
  30. </div>  
  31. <div class="form-row">  
  32. <div class="form-group col-md-6">  
  33. <input type="text" class="form-control form-contact" id="subject" placeholder="Subject" required />  
  34. </div>  
  35. <div class="form-group col-md-6">  
  36. <input type="text" class="form-control form-contact" id="contact" placeholder="Your Contact No." required />  
  37. </div>  
  38. </div>  
  39. <div class="form-group">  
  40. <textarea class="form-control form-contact-msg" rows="5" id="htmlContent" placeholder="Enter Your Message" required></textarea>  
  41. </div>  
  42. <button class="submit-contact" type="button" id="btnSend">Submit</button>  
  43. </form>  
  44. </div>  
  45. </div>  
  46. </div>  
  47. </div>  
  48. </div>  
  49. <div>  
  50. </div>  
  51. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>  
  52. <script type="text/javascript">  
  53. $(function () {  
  54. $("#btnSend").click(function (e) {  
  55. e.preventDefault();  
  56. var record = {  
  57. "htmlContent": $("#htmlContent").val(),  
  58. "toEmail": $("#toEmail").val(),  
  59. "subject": $("#subject").val(),  
  60. "htmlContent": $("#htmlContent").val(),  
  61. "contact": $("#contact").val(),  
  62. };  
  63. $.ajax({  
  64. url: '/Genric/SendMail',  
  65. type: "GET",  
  66. data: record,  
  67. contentType: "application/json; charset=utf-8",  
  68. success: function () {  
  69. $("#form").reset();  
  70. },  
  71. error: function () {  
  72. },  
  73. failure: function () {  
  74. }  
  75. });  
  76. });  
  77. });  
  78. </script>   
My result is 
 

Demo

Inbox

info@

4:19 PM (56 minutes ago)
 
to me
Demo  -not here UserName 

Answers (2)