Closed RobinWitt closed 1 year ago
Hi @RobinWitt you should either use new Mailjet(...)
syntax or the static method of the Mailjet client class Mailjet.apiConnect(....)
. You can use both require
and import
statements. Here're examples of possible usage:
const Mailjet = require("node-mailjet");
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
});
const request = mailjet
.post("send", { version: "v3.1" })
....
or
const Mailjet = require("node-mailjet");
const request = Mailjet
.apiConnect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
.....
or
import { Client } from "node-mailjet";
const mailjet = new Client({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
});
const request = mailjet
.post("send", { version: "v3.1" })
....
or
import { Client } from "node-mailjet";
const request = Client
.apiConnect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
....
or even
import * as Mailjet from "node-mailjet";
const mailjet = new Mailjet.Client({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
});
const request = mailjet
.post("send", { version: "v3.1" })
....
or
import * as Mailjet from "node-mailjet";
const request = Mailjet.Client
.apiConnect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE)
....
Please let us know if something is unclear.
thanks a lot!
Hello, I am currently trying to setup a Contact-Form forwarding handler that sends the formData via Mailjet to Email Client.
I am confused by the Setup guideline. There is "Basic Setup", "API-Setup" and "send your first Email". Each of these look different. I tried different methods, the closest I came to was an error in my console stating "API_KEY is required". (I checked, my env variables are working) What should I use to get it working when using an api handler route in next.js? Can I use "import" instead of "require"?
Thanks in advance
this is what my current code looks like: