Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

573
Vistas
Passing Vue.js form data to Nodemailer script with Axios

I have some form data in one of my Vue components that I want to pass on to my Nodemailer script so that data can be sent as an email. I'm trying to use Axios to do this.

Nothing is happening though as I don't actually know what I'm doing!

The Nodemailer script I have set up works when I execute the file in the command line. What I need is for it to execute when the form in my Vue.js component is submitted.

Here is my Nodemailer script -

"use strict";
const nodemailer = require("nodemailer");
require('dotenv').config();

// async..await is not allowed in global scope, must use a wrapper
async function main() {

  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    host: "smtp.gmail.com",
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: process.env.user, // generated ethereal user
      pass: process.env.password, // generated ethereal password
    },
  });

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: process.env.user, // sender address
    to: process.env.email, // list of receivers
    subject: 'Translation Suggestion', // Subject line
    text: "Hello world?", // plain text body
    html: "<p>Traditional: <br> Simplified: <br> Pinyin: <br> English: "
          
  });

  console.log("Message sent: %s", info.messageId);
  // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

  // Preview only available when sending through an Ethereal account
  console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
  // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}

main().catch(console.error);

And the function being called upon submit in my form component -

<button type="submit" @click="sendEmail" class="form__btn">Suggest</button>

sendEmail () {
          axios.post("localhost:3000/send-translation-suggest-email", () => {
            this.traditional,
            this.simplified,
            this.pinyin,
            this.english
          })
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To create a REST-API with express.js, first initialize a node.js-project (npm init [-y]). Then you install express.js (npm install express).

When you have your setup, you can create an index.js-file, the server. In it, you will have to adapt the content of the express Hello World example, so that the route it accepts is not GET / but POST /send-translation-suggest-email. Then make sure your server listens to port 3000 (as you specified in the client-side code).

In the listener to POST /send-translation-suggest-email, you can call the main-method from your other file (make sure to import the file properly, with node.js's require-syntax).

Then, you can call the backend server from the frontend as you wished.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda