I am looking to utilize mailjet for my contact form. I have installed it using "$ yarn add node-mailjet" and followed the steps provided. However, I am a bit confused about whether I am integrating mailjet correctly. Below is the code I am currently using:
contact.vue:
<form accept-charset="UTF-8" action="/contacto" class="row" method="post" id="contactForm">
<div class="col-sm-4">
<div class="input-group">
<input type="text" class="form-control" placeholder="Name" name="contact[name]" id="contact_name" required>
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
<div class="col-sm-4">
<div class="input-group">
<input type="email" class="form-control" placeholder="Email" name="contact[email]" id="contact_email" required>
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
<div class="col-sm-4">
<div class="input-group">
<input type="text" class="form-control" placeholder="Subject" name="contact[issue]" id="contact_issue">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
<div class="col-sm-12">
<div class="input-group textarea">
<textarea class="form-control" placeholder="Your Message" name="contact[comment]" id="contact_comment" required></textarea>
<span class="input-group-addon"><i class="fa fa-pencil"></i></span>
</div>
</div>
<div class="col-sm-12">
<input type="submit" value="Send Information" class="btn btn-danger active">
<!--<a href="#" class="btn btn-danger active" @click="send()">Send</a>-->
</div>
</form>
script:
export default {
}
var Mailjet = require('node-mailjet').connect('xxxxapi-keyxxx', 'xxxapi-secretxxxx');
// The third argument (the object) is not mandatory. Each configuration key is also optional
const mailjet = require('apiv3')
.connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE, {
url: 'api.mailjet.com', // default is the API url
version: 'v3.1', // default is '/v3'
perform_api_call: true // used for tests. default is true
}),
var sendEmail = Mailjet.post('send');
var emailData = {
'FromEmail': '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e68b9fa6838b878f8ac885898b">[email protected]</a>',
'FromName': 'My Name',
'Subject': 'Test with the NodeJS Mailjet wrapper',
'Text-part': 'Hello NodeJs !',
'Recipients': [{
'Email': '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a5b8a1adb0aca580a7ada1a9aceea3afad">[email protected]</a>'
}],
'Attachments': [{
"Content-Type": "text-plain",
"Filename": "test.txt",
"Content": "VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK", // Base64 for "This is your attached file!!!"
}]
},
sendEmail
.request(emailData)
.then(handlePostResponse)
.catch(handleError);
I would greatly appreciate it if you could review my code and let me know if there are any mistakes.