I would like to send a mail when I click a button. I have stored the mail I have to send it to in: localStorage.plMail My problem is, this ain't worked in my vue.js So I have to make it server side in a .js file. But I have no idea after researching how I can call a method from a .js file from my vue. I've tried to call the method from my index.js file in the store folder but as I said, no clue.
This is a part of my vue so far:
<template>
...
<td class="d-flex justify-content-around">
<button class="btn btn-danger btn-circle" type="button" @click="cancelMail(row)">
<!-- ❌ -->
<i class="fas fa-trash"></i>
</button>
<button class="btn btn-success btn-circle" type="button" @click="makeMail(row)">
<!-- ✅ -->
<i class="fas fa-check"></i>
</button>
</td>
...
</template>
<script>
export default {
name: "PlantsList",
components: { },
methods {
cancelMail(data) {
},
makeMail(data){
this.$store.dispatch('makeMail', data);
}
}
}
</script>
^That's not the whole code, it's shorten for good reasons.
This is how my folder structure looks like^
and this my mail logic:
const nodemailer = require('nodemailer');
const schedule = require('node-schedule');
var transporter = nodemailer.createTransport({
host: "**", // hostname
secure: false, // use SSL
port: **, // port for secure SMTP
tls: {
rejectUnauthorized: false
}
});
var mailOptions = {
from: 'anything@mail.com', // sender address
to: 'anything2@mail.com', // list of receivers
cc: '', // Comma separated list or an array
subject: 'test', // Subject line
html: '<b>Hello world </b>' // html body
};
const job = schedule.scheduleJob('45 * * * * *', function() {
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log("/sendmail error");
console.log(error);
//res.sendStatus(500);
return;
} else {
console.log("Message sent: " + info.response);line
socketTimeout: 30 * 1000 // 0.5 min: Time of inactivity until the connection is closed
transporter.close(); // shut down the connection pool, no more essages
//res.sendStatus(200);
}
transporter.close(); // shut down the connection pool, no more messages
});
})
