Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  4. <script>
  5. $(document).ready(function(){
  6. $("#myForm").hide();
  7. $("#sub").click(function(){
  8. if($("#myinp").val() == 1 ) {
  9. $("#myForm").hide();
  10. $("#new").text("Email sent without attachment");
  11. }
  12. else if ($("#myinp").val() == 2) {
  13. $("#myForm").show();
  14. $("#new").text("");
  15. }
  16. else {
  17. $("#myForm").hide();
  18. $("#new").text("Email Cannot be send");
  19. }
  20. });
  21. });
  22. </script>
  23. </head>
  24. <body>
  25.  
  26. <input type="number" id="myinp" placeholder="enter 1 or 2"/>
  27. <button id="sub">Send Mail</button>
  28. <form id="myForm" action="/sendForm" method="post" enctype="multipart/form-data">
  29. <input type="file" name="order" value="2" >
  30. <label > Select a file to upload </label>
  31. <input type="submit" value="Submit">
  32. </form>
  33. <div id="new"></div>
  34. </body>
  35. </html>
  36.  
  37. var request=require('request');
  38. var qs = require('querystring');
  39. var multiparty=require('multiparty');
  40. var util=require('util');
  41. var http=require('http');
  42. var fs=require('fs');
  43. const nodemailer=require('nodemailer');
  44. const xoauth2=require('xoauth2');
  45. var transporter=nodemailer.createTransport({
  46. service:'gmail',
  47. auth:{
  48. type: 'OAuth2',
  49. user:'SenderMail@gmail.com',
  50. clientId:'ClienId from google console developers website',
  51. clientSecret:'clientSecret from google console developers website ',
  52. refreshToken:'RefreshToken from Oauth2 Playground website',
  53. accessToken:'accessToken from Oauth2 Playground website'
  54. },
  55. });
  56. const server=http.createServer((req,res)=>{
  57. if (req.url === '/sendForm' && req.method === 'POST') {
  58. var body = "";
  59. req.on('data', function (chunk) {
  60. body += chunk;
  61. });
  62. req.on('end', function () {
  63. var mailOptions={
  64. from:' <sender'smail@gmail.com>',
  65. to:'Receiver'smail@gmail.com',
  66. subject:'Sample mail',
  67. text:'Hello !!!!!!!!!!!!!',
  68. };
  69. transporter.sendMail(mailOptions,function(err,res){
  70. if(err){
  71. console.log('Error');
  72. }
  73. else{
  74. console.log('Email Sent');
  75. }
  76. });
  77. res.end("successfully submitted");
  78. });
  79. }
  80. fs.readFile("./switchreal.html",(err,data)=>{
  81.  
  82. res.writeHead(200, {'content-type': 'text/html','Content-Length':data.length});
  83. res.end(data);
  84. });
  85. }).listen(3000,function(){
  86. console.log("Server Listening on 3000");
  87. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement