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.