Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbenjoy2 opened this issue Mar 4, 2022 · 0 comments
Open

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

jbenjoy2 opened this issue Mar 4, 2022 · 0 comments

Comments

@jbenjoy2
Copy link

jbenjoy2 commented Mar 4, 2022

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 }),
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant