我的网站允许用户通过Drupal MailChimp模块使用API订阅MailChimp列表。但是,如果用户通过电子邮件中的链接取消订阅,然后决定通过访问我的网站并选中“订阅”框重新订阅,MailChimp会回复:
xxx@xxx.xxx由于取消订阅、退信或合规审查而处于合规状态,无法进行订阅。
假设用户真的想重新订阅,该怎么办?
xxx@xxx.xxx由于取消订阅、退信或合规审查而处于合规状态,无法进行订阅。
假设用户真的想重新订阅,该怎么办?
将成员的状态设置为待处理
。这样应该会重新发送确认邮件。
首先从响应中获取状态,如果是取消订阅,则更新列表。这样就可以解决问题啦 ;)
const mailchimp = require("@mailchimp/mailchimp_marketing");
const md5 = require("md5");
router.post("/newsletter-subscribe", asyncWrapper(async (req, res) => {
mailchimp.setConfig({
apiKey: "e4ef******62c481-us17",
server: "us17",
});
const subscriber_hash = md5(email.toLowerCase());
const list_id = '44b****47';
let response = await mailchimp.lists.setListMember(
list_id,
subscriber_hash,
{
email_address: email,
status_if_new: 'subscribed',
}
);
if(response.status=='unsubscribed'){
response = await mailchimp.lists.updateListMember(
list_id,
subscriber_hash,
{status: 'subscribed'}
);
}
return res.json({'subscribed': response.status});
}));
一个选择是使用API:首先将其设置为待定,然后将其设置为订阅。将用户设置为待定似乎会发送确认电子邮件,但您可以通过将其设置为已订阅来确保确认。
我在下面包含了一个Python脚本来重新订阅一系列电子邮件。
import hashlib
import requests
import time
# Replace these with your API key and List ID
API_KEY = 'cc2355555555555555555555555555-us1'
LIST_ID = 'c555555555'
# Replace this with your datacenter, e.g. 'us6'
DATACENTER = 'us1'
# List of email addresses to resubscribe
email_addresses = ['email@address.com','email2@address.com']
# Get the total number of email addresses
total_addresses = len(email_addresses)
# Loop through email addresses
for index, email in enumerate(email_addresses):
# Create md5 hash of the lowercase email address
email_hash = hashlib.md5(email.lower().encode()).hexdigest()
# API URL to update the member
url = f'https://{DATACENTER}.api.mailchimp.com/3.0/lists/{LIST_ID}/members/{email_hash}'
# Data to update (set status to 'pending' to send opt-in confirmation email)
data_pending = {
'status': 'pending',
'email_address': email
}
# Make a PUT request to update the member to pending
response = requests.put(url, json=data_pending, auth=('anystring', API_KEY))
# Print the response
print(f'Response for {email} (pending): {response.status_code} - {response.text}')
# Optional: Wait for a few seconds before updating the status to subscribed
time.sleep(5)
# Data to update (set status to 'subscribed')
data_subscribed = {
'status': 'subscribed',
'email_address': email
}
# Make a PUT request to update the member to subscribed
response = requests.put(url, json=data_subscribed, auth=('anystring', API_KEY))
# Print the response
print(f'Response for {email} (subscribed): {response.status_code} - {response.text}')
# Calculate and print the progress percentage
progress_percentage = (index + 1) / total_addresses * 100
print(f'Progress: {progress_percentage:.2f}%')