Guest User

Untitled

a guest
Feb 4th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3. const nodemailer = require('nodemailer');
  4. const path = require('path');
  5.  
  6. const app = express();
  7.  
  8. app.use('/', express.static(path.join(__dirname, 'render')));
  9.  
  10. app.use(bodyParser.urlencoded({ extended: false }));
  11. app.use(bodyParser.json());
  12.  
  13. app.get('/', (req, res) => {
  14. res.sendFile(path.join(__dirname+'/render/index.html'));
  15. });
  16. app.post('/send', (req, res) => {
  17. const email = {
  18. name: req.body.name,
  19. email: req.body.email,
  20. phone: req.body.phone,
  21. startPoint: req.body.startPoint,
  22. endPoint: req.body.endPoint,
  23. dateTime: req.body.dateTime
  24. };
  25. // create reusable transporter object using the default SMTP transport
  26. let transporter = nodemailer.createTransport({
  27. host: 'mail.advertidea.pl',
  28. port: 587,
  29. secure: false, // true for 465, false for other ports
  30. auth: {
  31. user: 'emailIsCorrect', // generated ethereal user
  32. pass: 'passIsCorrect' // generated ethereal password
  33. },
  34. tls:{
  35. rejectUnauthorized:false
  36. }
  37. });
  38.  
  39. // mail for admin
  40. // setup email data with unicode symbols
  41. let adminMailOptions = {
  42. from: '"GoodTransfer" <[email protected]>', // sender address
  43. to: '[email protected]', // list of receivers
  44. subject: 'New transfer request', // Subject line
  45. html: `<p>${email.name}, asks for transfer.<p><br>
  46. <p>Transfer details:</p><br><br>
  47. <p>starting point: ${email.startPoint}</p>
  48. <p>ending point: ${email.endPoint}</p>
  49. <p>date and time: ${email.dateTime}</p><br><br>
  50. <p>clients email: ${email.email}</p>
  51. <p>phone number: <a href="tel:${email.phone}">${email.phone}</a></p>` // html body
  52. };
  53.  
  54. // send mail with defined transport object
  55. transporter.sendMail(adminMailOptions, (error, info) => {
  56. if (error) {
  57. return console.log(error);
  58. }
  59. console.log('Message sent: %s', info.messageId);
  60. console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
  61. });
  62.  
  63. import Vue from 'vue';
  64. import Vuex from 'vuex';
  65.  
  66. Vue.use(Vuex);
  67.  
  68. export default new Vuex.Store({
  69. state: {
  70. email: {
  71. name: '',
  72. phone: '',
  73. startPoint: '',
  74. endPoint: '',
  75. date: new Date().toISOString().substr(0, 10),
  76. },
  77. },
  78. getters: {
  79. email: state => state.email,
  80. },
  81. mutations: {
  82. updateEmail(state, email) {
  83. this.state.email = email;
  84. },
  85. },
  86. actions: {
  87.  
  88. },
  89. });
  90.  
  91. import axios from 'axios';
  92.  
  93. export default {
  94. name: 'Book',
  95. data() {
  96. return {
  97. newEmail: '',
  98. valid: false,
  99. emailRules: [
  100. v => !!v || 'E-mail is required',
  101. v => /.+@.+/.test(v) || 'E-mail must be valid',
  102. ],
  103. };
  104. },
  105. computed: {
  106. email: {
  107. get() {
  108. return this.$store.state.email;
  109. },
  110. set(value) {
  111. this.$store.commit('updateMessage', value);
  112. },
  113. /* return this.$store.getters.email; */
  114. },
  115. },
  116. methods: {
  117. submitForm() {
  118. console.log(JSON.stringify(this.email));
  119. axios.post('http://goodtransfer.pixelart.pl/send', JSON.stringify(this.email), 'json')
  120. .then((res) => {
  121. console.log(res);
  122. console.log(res.data);
  123. });
  124. },
  125. },
  126. };
Add Comment
Please, Sign In to add comment