顯然,Mailchimp只會發送通知電子郵件,如果你有一個雙選擇啓用表單。
所以,如果您使用的API,它不會觸發響應。
我的解決方案是使用Mailchimp Webhooks來ping我的快遞服務器然後給我發電子郵件。
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 protected]>', // sender address
to: '[email protected]', // 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')
})
})
它使用Nodemailer NPM Module發送電子郵件廣告GMAIL作爲可mailgun服務或sendgrid等