如何使用 MailChimp 发送电子邮件 API

How to send email using MailChimp API

我正在 nodejs 中创建一个应用程序以使用 MailChimp 发送电子邮件。我尝试使用 https://apidocs.mailchimp.com/sts/1.0/sendemail.func.php 但将其更改为使用 3.0 api 因为 1.0 似乎不再有效(大惊喜)。我已经使用

设置了我的应用程序
var apiKey = '<<apiKey>>',
        toEmail = '<<emailAddress>>',
        toNames = '<<myName>>',
        message = {
            'html': 'Yo, this is the <b>html</b> portion',
            'text': 'Yo, this is the *text* portion',
            'subject': 'This is the subject',
            'from_name': 'Me!',
            'from_email': '',
            'to_email': toEmail,
            'to_name': toNames
        },
        tags = ['HelloWorld'],
        params = {
            'apikey': apiKey,
            'message': message,
            'track_opens': true,
            'track_clicks': false,
            'tags': tags
        },
        url = 'https://us13.api.mailchimp.com/3.0/SendEmail';
needle.post(url, params, function(err, headers) {
    if (err) {
                console.error(err);
            }
            console.log(headers);
    }
});

我不断收到 401 响应(未授权,因为我没有正确发送 API 密钥)

由于服务器的限制,我不得不使用needle。

您应该在 MailChimp API 3.0 中使用 HTTP 基本身份验证。

needle.get('https://<dc>.api.mailchimp.com/3.0/<endpoint>', { username: 'anystring', password: 'your_apikey' },
  function(err, resp) {
      // your code here...
});

编辑

@TooMuchPete 是对的,SendMail 端点在 MailChimp API v3.0 中无效。我没有注意到这一点,我已经编辑了我的答案。

API v3.0 中没有 "SendEmail" 端点。 MailChimp 的 STS 是其 Mandrill 交易服务的前身,可能仅适用于拥有现有 STS 活动的用户帐户。无法创建新的 STS 活动。如果你有一个按月付费的 MailChimp 帐户,你应该看看 Mandrill。如果没有,我在 Mailgun 上运气不错。