How to handle email changes done at CiviCRM?
Mailchimp provides a UX for members to update their email address. This results in a webhook which will add the address to the contact, if new, and update our cache table with the new email address.
However any changes to any email in CiviCRM do not affect the process.
One of the challenges is that there's no "change email" UX in CiviCRM (for good reasons). You can edit an email, you can delete an email, you can add a new email, but all these are separate operations that might not have anything to do with someone changing the email that they use on a particular list.
One possibility would be this:
-
add a hook so that whenever an email is updated/created/deleted, the contact's mailchimp connections are flagged as to be included in the next sync run. Which then...
-
After checking that the contact we have for the email still exists (here we're assuming it does), then it should go on to check that the email mailchimp has still exists on the CiviCRM contact record. If so, all is well, nothing to do. If not...
-
This now looks like we need to change the email address at Mailchimp. We could make the assumption that this is a fairly rare case (even on a big list), and that we're therefore OK to action the change with a single synchronous call to Mailchimp's API, followed by updating our cache table with the new address.
We would select the address to use by first picking the first not-on-hold: Bulk Mail one, then the primary, then any of them, as we do for other subscriptions.
If, however, there are no email addresses at CiviCRM that we can use then we should remove them from the group? Or mark the sync as a fail?