nodemailer-mailgun-transport icon indicating copy to clipboard operation
nodemailer-mailgun-transport copied to clipboard

mailgun-js requiring html or text field even when using template

Open jbenjoy2 opened this issue 2 years ago • 0 comments

Hi there

I'm trying to get my mailgun template to send, but when I pass in the template name as the option, I get the following error:

Error: Need at least one of 'text' or 'html' parameters specified

When I do supply an argument, it overrides the use of the template.

Stack: "express": "^4.17.1", "mailgun-js": "^0.22.0", "nodemailer": "^6.7.2", "nodemailer-mailgun-transport": "^1.4.0",

Here is my code:

const nodeMailer = require("nodemailer");
const mailGun = require("nodemailer-mailgun-transport");
const express = require("express");
const router = new express.Router();

const auth = {
  auth: {
    api_key: process.env.MAILGUN_API_KEY,
    domain: process.env.MAILER_DOMAIN,
  },
};

let mailgunAuth = mailGun(auth);
let transporter = nodeMailer.createTransport(mailgunAuth);

router.post("/collaboration", async (req, res, next) => {
  const { senderUN, recipientUN, toEmail } = req.body;
  const options = {
    from: process.env.MAILER_FROM,
    to: toEmail,
    subject: `New collaboration request from ${senderUN}!`,
    template: "collaboration_request",
    html: "<h1>Hello World</h1>",
    "h:X-Mailgun-Variables": JSON.stringify({ sender: senderUN }),
  };

jbenjoy2 avatar Mar 04 '22 19:03 jbenjoy2