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

我在nodejs中创build一个应用程序来使用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密钥)

由于服务器上的限制,我必须使用针。

API v3.0中没有“SendEmail”端点。 MailChimp的STS是其Mandrill事务服务的前缀,并且可能只适用于具有现有STS活动的用户帐户。 没有新的STS活动可以创build。 如果你有一个每月付费的MailChimp账户,你应该看看Mandrill。 如果没有,我已经与Mailgun祝好运了。

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

 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中无效。 我没有注意到,我已经编辑了我的答案。