当新订户通过Mailchimp API加入列表时发送电子邮件通知

时间:2017-08-02 13:28:03

标签: javascript forms mailchimp mailchimp-api-v3.0

我正在尝试在用户注册我的邮件列表时收到电子邮件通知。

这是一个与Mailchimp API集成的简单表单,但是当用户注册时我没有收到电子邮件,用户也没有收到“欢迎”电子邮件。我认为这与双重选择有关,但我希望简化它。

我想也许webhooks然后使用sendgrid之类的东西发送自定义电子邮件,但我想我不会使用Mailchimps标准模板。

这有一个简单的解决方案吗?

1 个答案:

答案 0 :(得分:0)

显然,如果您启用了双重选择表单,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等。

相关问题