Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script>
- $(document).ready(function(){
- $("#myForm").hide();
- $("#sub").click(function(){
- if($("#myinp").val() == 1 ) {
- $("#myForm").hide();
- $("#new").text("Email sent without attachment");
- }
- else if ($("#myinp").val() == 2) {
- $("#myForm").show();
- $("#new").text("");
- }
- else {
- $("#myForm").hide();
- $("#new").text("Email Cannot be send");
- }
- });
- });
- </script>
- </head>
- <body>
- <input type="number" id="myinp" placeholder="enter 1 or 2"/>
- <button id="sub">Send Mail</button>
- <form id="myForm" action="/sendForm" method="post" enctype="multipart/form-data">
- <input type="file" name="order" value="2" >
- <label > Select a file to upload </label>
- <input type="submit" value="Submit">
- </form>
- <div id="new"></div>
- </body>
- </html>
- var request=require('request');
- var qs = require('querystring');
- var multiparty=require('multiparty');
- var util=require('util');
- var http=require('http');
- var fs=require('fs');
- const nodemailer=require('nodemailer');
- const xoauth2=require('xoauth2');
- var transporter=nodemailer.createTransport({
- service:'gmail',
- auth:{
- type: 'OAuth2',
- user:'SenderMail@gmail.com',
- clientId:'ClienId from google console developers website',
- clientSecret:'clientSecret from google console developers website ',
- refreshToken:'RefreshToken from Oauth2 Playground website',
- accessToken:'accessToken from Oauth2 Playground website'
- },
- });
- const server=http.createServer((req,res)=>{
- if (req.url === '/sendForm' && req.method === 'POST') {
- var body = "";
- req.on('data', function (chunk) {
- body += chunk;
- });
- req.on('end', function () {
- var mailOptions={
- from:' <sender'smail@gmail.com>',
- to:'Receiver'smail@gmail.com',
- subject:'Sample mail',
- text:'Hello !!!!!!!!!!!!!',
- };
- transporter.sendMail(mailOptions,function(err,res){
- if(err){
- console.log('Error');
- }
- else{
- console.log('Email Sent');
- }
- });
- res.end("successfully submitted");
- });
- }
- fs.readFile("./switchreal.html",(err,data)=>{
- res.writeHead(200, {'content-type': 'text/html','Content-Length':data.length});
- res.end(data);
- });
- }).listen(3000,function(){
- console.log("Server Listening on 3000");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement