Guest User

Untitled

a guest
Feb 4th, 2019
206
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" <test@advertidea.pl>', // sender address
  43. to: 'kamil.grzaba@gmail.com', // 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. email: 'test@test.pl',
  73. phone: '',
  74. startPoint: '',
  75. endPoint: '',
  76. date: new Date().toISOString().substr(0, 10),
  77. },
  78. },
  79. getters: {
  80. email: state => state.email,
  81. },
  82. mutations: {
  83. updateEmail(state, email) {
  84. this.state.email = email;
  85. },
  86. },
  87. actions: {
  88.  
  89. },
  90. });
  91.  
  92. import axios from 'axios';
  93.  
  94. export default {
  95. name: 'Book',
  96. data() {
  97. return {
  98. newEmail: '',
  99. valid: false,
  100. emailRules: [
  101. v => !!v || 'E-mail is required',
  102. v => /.+@.+/.test(v) || 'E-mail must be valid',
  103. ],
  104. };
  105. },
  106. computed: {
  107. email: {
  108. get() {
  109. return this.$store.state.email;
  110. },
  111. set(value) {
  112. this.$store.commit('updateMessage', value);
  113. },
  114. /* return this.$store.getters.email; */
  115. },
  116. },
  117. methods: {
  118. submitForm() {
  119. console.log(JSON.stringify(this.email));
  120. axios.post('http://goodtransfer.pixelart.pl/send', JSON.stringify(this.email), 'json')
  121. .then((res) => {
  122. console.log(res);
  123. console.log(res.data);
  124. });
  125. },
  126. },
  127. };
Add Comment
Please, Sign In to add comment