Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. var nodemailer = require('nodemailer');
  2. var bodyParser = require('body-parser');
  3. var express = require('express');
  4. var app = express();
  5.  
  6. app.use(bodyParser.urlencoded({ extended: true }));
  7.  
  8. app.post('/contact', function (req, res) {
  9. var mailOpts, smtpConfig;
  10. //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
  11. smtpConfig = nodemailer.createTransport('SMTP', {
  12. service: 'Gmail',
  13. auth: {
  14. user: "g.campbell269@gmail.com",
  15. pass: "102193gc"
  16. }
  17. });
  18. //Mail options
  19. mailOpts = {
  20. from: req.query.name + ' <' + req.query.email + '>', //grab form data from the request body object
  21. to: 'g.campbell269@gmail.com',
  22. subject: 'Website contact form',
  23. text: req.query.message
  24. };
  25. smtpConfig.sendMail(mailOpts, function (error, response) {
  26. //Email not sent
  27. if (error) {
  28. res.end("Email send failed");
  29. //res.render('contact', { title: 'Raging Flame Laboratory - Contact', msg: 'Error occured, message not sent.', err: true, page: 'contact' })
  30. //console.log("error");
  31. }
  32. //Yay!! Email sent
  33. else {
  34. res.end("Email send successfully");
  35. //res.render('contact', { title: 'Raging Flame Laboratory - Contact', msg: 'Message sent! Thank you.', err: false, page: 'contact' })
  36. //console.log("success");
  37. }
  38. });
  39. });
  40.  
  41. app.listen(8081, function() {
  42. console.log('Server running at http://127.0.0.1:8081/');
  43. });
  44.  
  45. <form action="http://127.0.0.1:8087/contact" method="post">
  46. <b>send us a quote</b></br>
  47. <input type="text" name="name" id="name" value="Name"></br>
  48. <!--input type="text" name="bname" id="bname" value="Business Name"></br>-->
  49. <input type="text" name="email" id="email" value="Email Address"></br>
  50. <textarea name="message" id="message" cols="30" rows="10">Enter detailed information here</textarea></br>
  51. <input type="submit" name="Submit" id="Submit" value="send message">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement