Issues using Mailgun with Payload for Email

default discord avatar
just_board
5 months ago
7

Hello there, I have spent a great deal of time looking over the docs


https://payloadcms.com/docs/authentication/operations
https://payloadcms.com/docs/email/overview#use-an-email-service
https://nodemailer.com/smtp/
https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-via-api

I have tried two different ways to configure the email and have not yet been successful, if anyone sees what I am doing wrong and could be of some assistance that would be very much appreciated. Feeling very human and open to being humbled. 😄



import express from "express";
import payload from "payload";
require("dotenv").config();
const app = express();

// import Mailgun from "mailgun.js";
// import formData from "form-data";
// require("form-data");
// require("mailgun.js");
// const mailgunKey = process.env.MAILGUN_API_KEY;
// const mailgunDomain = process.env.MAILGUN_DOMAIN;
// const mailgunForm = new Mailgun(formData);
// const mg = mailgunForm.client({
//   username: "api",
//   key: process.env.MAILGUN_API_KEY,
// });

require('nodemailer');
require('nodemailer-mailgun-transport');
import nodemailer from 'nodemailer';
import mg from 'nodemailer-mailgun-transport'; 
const mailgunKey = process.env.MAILGUN_API_KEY;
const mailgunDomain = process.env.MAILGUN_DOMAIN;
const auth = {
  auth: {
    api_key: mailgunKey,
    domain: mailgunDomain
  }
}

const transport =  nodemailer.createTransport(mg(auth));

// Initialize Payload
payload.init({
  secret: process.env.PAYLOAD_SECRET,
  mongoURL: process.env.MONGODB_URI,
  express: app,
 
  email: {
    // transportOptions: mg,
     transport: transport,
    //logMockCredentials: true,
    fromName: process.env.FROM_NAME,
    fromAddress: process.env.FROM_ADDRESS,
  },
  onInit: () => {
    payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
  },
});

// Add your own express routes here
// Redirect root to Admin panel
app.get("/", (_, res) => {
  res.redirect("/admin");
});

app.listen(3001);
  • default discord avatar
    notchr
    5 months ago

    @just_board do you receive any specific error messages?

  • default discord avatar
    just_board
    5 months ago

    Oh I am just an idiot, left it over the weekend, came back monday and it was working

  • default discord avatar
    jarrod69420
    5 months ago

    I’m not sure what we should do with these threads. Should we delete them? Make a special tag for them?



    If we mark it as “answered” it will end up in community help on our website. But should it?? I’m not sure

  • default discord avatar
    notchr
    5 months ago

    It's tough because a lot of times people come back to a related thread and want to continue the discussion

  • default discord avatar
    jarrod69420
    5 months ago

    I agree, we could make a 'non-issue' tag or similar

  • default discord avatar
    just_board
    5 months ago

    Yo keep threads like this, I use them all the time as adhoc examples, suuuuuuper valuble to me as a developer

  • default discord avatar
    jarrod69420
    5 months ago

    @just_board yeah likely we will use a tag. I have no problem with your post, it’s just that you asked a question and then figured it out yourself but didn’t provide an answer, which is fine. I’m just not sure we should mark it as “answered” bc then it will end up in community help

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.