显然,如果您启用了双重选择表单,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@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')
})
})
这使用Nodemailer NPM Module 发送电子邮件广告 GMAIL 作为服务,可以是 mailgun 或 sendgrid 等。