【问题标题】:Send email notification when a new subscriber joins list via Mailchimp API当新订阅者通过 Mailchimp API 加入列表时发送电子邮件通知
【发布时间】:2018-01-09 18:17:42
【问题描述】:

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

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

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

有没有简单的解决方案?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-11-15
      • 2018-07-13
      • 2018-01-03
      • 2015-12-18
      • 2023-03-22
      • 2016-06-12
      • 2011-07-14
      • 2015-11-20
      • 2015-10-21
      相关资源
      最近更新 更多