orliesaurus / nodemailer-mailgun-transport

nodemailer is an amazing node module to send emails within any of your nodejs apps. This is the transport plugin that goes with nodemailer to send email using Mailgun 🔫
MIT License
880 stars 97 forks source link

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

Open jbenjoy2 opened 2 years ago

jbenjoy2 commented 2 years ago

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 }),
  };