Guest User

API Demo

a guest
Dec 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>MailboxLayer Email Checker Proof of Concept</title>
  4. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  5. <style>
  6. * {
  7. font-size: 18px;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <div class="row">
  14. <div class="col-md-8">
  15. <p>Enter the email you wish to be checked:</p>
  16. <input class="form-control my-2" type="email" id="email" placeholder="[email protected]">
  17. <button type="button" id="button" class="btn btn-primary my-2">Submit</button>
  18. <div class="alert my-4" role="alert" id="response">
  19. <b></b>
  20. <br>
  21. <pre class="text-left">
  22.  
  23. </pre>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="row">
  28. <div class="col-md-8">
  29. <p>This API is found at https://mailboxlayer.com is used for evaluating emails and how legitimate the email could be.
  30. A use case for this would be verifying people signing up for an website are using emails that are valid and less likely to be spam the service.
  31. This will ensure that real people are signing up rather than one person generating email accounts and using the service maliciously.
  32. The api will generate a score from the email address and provide the user the score from information such are what kind of domain is it created from and if it is free or not
  33. which will tell if the email is of a bad quality which is not worth sending things to or approving or is it a good quality email
  34. worth being approved.
  35. </p>
  36. </div>
  37. </div>
  38. </div>
  39. <script>
  40. const API_KEY = 'ac0a044916b9b20806a2f4e7a14d270b';
  41. (function(){
  42. document.getElementById("button").addEventListener('click', function() {
  43. console.log(this);
  44. const userEmail = document.getElementById('email').value;
  45. const outputField = document.getElementById('response');
  46.  
  47. fetch('https://apilayer.net/api/check?access_key=' + API_KEY + '&email=' + userEmail)
  48. .then(response => {
  49. return response.json();
  50. })
  51. .then(json => {
  52. console.log(json);
  53. outputField.classList.remove('alert-danger');
  54. outputField.classList.remove('alert-success');
  55. outputField.classList.remove('alert-warning');
  56. if (json.format_valid) {
  57. outputField.classList.add('alert-success');
  58. outputField.querySelector('b').innerText = 'Success';
  59. } else {
  60. outputField.classList.add('alert-warning');
  61. outputField.querySelector('b').innerText = 'Warning - Invalid Email Format';
  62. }
  63. outputField.querySelector('pre').innerText = JSON.stringify(json, null, 2);
  64. })
  65. .catch(error => {
  66. outputField.classList.remove('alert-danger');
  67. outputField.classList.remove('alert-success');
  68. outputField.classList.remove('alert-warning');
  69. outputField.classList.add('alert-danger');
  70. outputField.querySelector('b').innerText = 'Error';
  71. outputField.querySelector('pre').innerText = error;
  72. });
  73. });
  74. })();
  75. </script>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment