Closed joseadame closed 2 years ago
Hello @joseadame
I tried to reproduce your error but I didn't receive the same and deployed functions that used node-mailjet@3.1.1
without any errors.
Below I provided my source files and the result of deploying and requests to Firebase Functions:
My package.json
:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "12"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0",
"node-mailjet": "^3.3.1"
},
"devDependencies": {
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
My index.js
:
const functions = require("firebase-functions");
const Mailjet = require("node-mailjet");
exports.helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
exports.testMailjet = functions.https.onRequest((request, response) => {
const mailjet = Mailjet
.connect(
"public_key",
"private_key"
);
const fromEmail = "pilot@mailjet.com"; // here your email
const toEmail = "passenger@mailjet.com"; // here your email
const emailRequest = mailjet
.post("send")
.request({
"FromEmail": fromEmail,
"FromName": "Pilot",
"Subject": "Hello world from Firebase and Mailjet",
"Text-part": "Hello World",
"Recipients": [
{
Email: toEmail,
},
],
});
functions.logger.debug("Start send email", {structuredData: true});
emailRequest
.then((result) => {
functions.logger.info("Email sent!", {structuredData: true});
response.status(201).send(result);
})
.catch((err) => {
functions.logger.error("Email not send", {structuredData: true});
response.status(500).send(err);
});
});
This is my deploy logs:
Response for helloWorld
endpoint:
Hello from Firebase!
Response for testMailjet
endpoint:
{
"response": {
"req": {
"method": "POST",
"url": "https://api.mailjet.com/v3/send",
"data": {
"FromEmail": "pilot@mailjet.com",
"FromName": "Pilot",
"Subject": "Hello world from Firebase and Mailjet",
"Text-part": "Hello World",
"Recipients": [
{
"Email": "passenger@mailjet.com"
}
]
},
"headers": {
"user-agent": "mailjet-api-v3-nodejs/3.3.1",
"content-type": "application/json",
"authorization": "Basic OWQ0YWVkOTU0ZGI5YTY2YTkxNDAxMjJhYTI4Tk3OWM1MTdkYTFkYmE1NmE0NTY0YjUyMDhiN2M="
}
},
"header": {
"date": "Mon, 25 Jul 2022 12:52:32 GMT",
"content-type": "application/json",
"content-length": "151",
"connection": "close"
},
"status": 200,
"text": "{ \"Sent\" : [{ \"Email\" : \"passenger@mailjet.com\", \"MessageID\" : 1152921517897215880, \"MessageUUID\" : \"3aab11a5-37cb-4099-86c0-439bbf081cce\" }] }\n"
},
"body": {
"Sent": [
{
"Email": "passenger@mailjet.com",
"MessageID": "1152921517897215880",
"MessageUUID": "3aab11a5-37cb-4099-86c0-439bbf081cce"
}
]
}
}
We added the Firebase Functions
example-app for you and other users who could want to use node-mailjet
with Firebase Functions
.
In this example-app we used:
Firebase
node v14node-mailjet
- v5.1.0
helloWorld
- a simple function that return response with text Hello from Firebase!
sendHelloWorld
- function that use mailjet library for send an email based on data that saved in your function and return response with result of sendingsendEmail
- function that use mailjet library for send an email and return response with result of sending that based on _query string data - sendEmail?from=$FROM_EMAIL&to=$TO_EMAIL&subject=$SUBJECT
_
Hi! When a try to deploy a Firebase function that uses node-mailjet with node 12 it throws de following error:
I have the following versions in package.json