13

My site allows users to subscribe to MailChimp lists using the API via Drupal MailChimp module. But if a user unsubscribes by following the link in the email, and subsequently decides to re-subscribe by visiting my website and checking the "subscribe" box, MailChimp responds with

xxx@xxx.xxx is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed.

What is the solution assuming the user really wants to re-subscribe?

ekad
  • 14,436
  • 26
  • 44
  • 46
Hugh Wormington
  • 305
  • 1
  • 2
  • 10
  • 2
    They have to take the action to resubscribe. Any attempt to resubscribe them manually or phishing to get them to resubscribe is beyond the terms of the Mailchimp agreement. They have to go through the process again, basically. [Useful Compliance tips](http://kb.mailchimp.com/accounts/compliance-tips/general-compliance-tips) – scoopzilla Feb 10 '17 at 17:46

4 Answers4

18

Set the member's status to pending. That should resend the opt-in email.

nmit026
  • 3,024
  • 2
  • 27
  • 53
  • 1
    1. Setting the user status to pending with the API triggers a MailChimp opt-in email, and the user will have to confirm by clicking the link in the email. Before you add or update the user via API, you should first query the MC API to see if this email address has ever opted-out. If so, then set them to pending and trigger the MC opt-in confirmation email. If the email has never signed up, then set them to subscribed and you will not trigger an opt-in confirmation email - the user will be signed up If the email is currently opted-in and hasn't unsubscribed then just update – Mike Ferrari May 26 '21 at 06:38
  • @MikeFerrari - "If the email has never signed up" then they won't be in a compliance state. – But those new buttons though.. Dec 07 '22 at 18:11
  • Rolling this back as the original answer was fine and is still valid as of 12-2022. I've been using MC API for years and this behaviour has never changed to my knowledge. – But those new buttons though.. Dec 07 '22 at 18:13
  • @EatenbyaGrue - True, our case was different. There was an error in a Shopify plugin that unsubscribed users from our MailChimp list if they didn't check a box to subscribe every time at checkout. Users didn't unsubscribe, the bug unsubscribed them, and we couldn't fix code that we didn't own. – Mike Ferrari Dec 15 '22 at 17:19
2

If we need to resubscribe an email which has been unsubscribed,

We need to make a put call with either of the following options:

  1. {"status" : "subscribed"} Will resubscribe the email
  2. {"status" : "pending"} Will send a confirmation email for resubscription.

The API endpoint must consist of md5 hash like(/lists/list_id/members/md5hash)

TheViralGriffin
  • 421
  • 1
  • 8
  • 21
0

First get the status from response, if it is unsubscribed then update the list.This will do the trick ;)

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});


}));
mlhazan
  • 1,116
  • 2
  • 15
  • 24
  • I got email@address.com is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed. I posted a solution for what worked – frazras Jun 26 '23 at 19:07
0

One option is to use the API: First, set them to pending, then set them to subscribe. Setting the user to pending will apparently send a confirmation email, but you can ensure confirmation by setting them as subscribed.

I included a Python script below to resubscribe a list of emails

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}%')
frazras
  • 5,928
  • 4
  • 30
  • 40