2

I'm trying to receive an email notification when a user signs up to my mailing list.

It's a simple form integrated with the Mailchimp API however I do not receive an email when a user signs up, nor does the user get a "welcome" email. I believe it's something to do with double opt-in but would like to make it simple.

I thought about perhaps webhooks to then send a custom email using something like sendgrid but then I guess I don't get to use Mailchimps standard templates.

Is there a simple solution for this?

Karl Taylor
  • 4,839
  • 3
  • 34
  • 62

1 Answers1

0

Apparently, Mailchimp only sends notification emails if you have a double opt in form enabled.

So if you're using the API, it won't trigger a response.

My solution was to use the Mailchimp Webhooks to ping my express server to then email me.

const nodemailer = require('nodemailer')

app.post('/mailchimp-webhook', (req, res) => {
  console.log(req.body['data[email]'])
  console.log('webhook')
  let transporter = nodemailer.createTransport({
    service: 'gmail',
    port: 465,
    secure: true, // secure:true for port 465, secure:false for port 587
    auth: {
      user: process.env.GMAIL_USERNAME,
      pass: process.env.GMAIL_PASSWORD
    }
  })

  let mailOptions = {
    from: '"Email Notifications " <email@address.com>', // sender address
    to: 'email@addresss.com', // list of receivers
    subject: 'You have a new subscriber!', // Subject line
    text: `${req.body['data[email]']}`, // plain text body
    html: `${req.body['data[email]']}` // html body
  }

  transporter.sendMail(mailOptions, (error, info) => {
    if (error) return console.log(error, 'error')
    else console.log(info, 'here')
  })
})

This uses the Nodemailer NPM Module to send emails ad GMAIL as the service which could be mailgun or sendgrid etc.

Karl Taylor
  • 4,839
  • 3
  • 34
  • 62