def METHOD_NAME(bounced_addresses, message_id):
    from corehq.apps.sms.models import MessagingEvent, MessagingSubEvent
    from corehq.apps.users.models import Invitation, InvitationStatus
    if isinstance(message_id, str) and Invitation.EMAIL_ID_PREFIX in message_id:
        try:
            invite = Invitation.objects.get(uuid=message_id.split(Invitation.EMAIL_ID_PREFIX)[1])
        except Invitation.DoesNotExist:
            pass
        else:
            invite.email_status = InvitationStatus.BOUNCED
            invite.save()
    else:
        try:
            subevent = MessagingSubEvent.objects.get(id=message_id)
        except MessagingSubEvent.DoesNotExist:
            pass
        else:
            metrics_counter('commcare.messaging.email.preemptively_bounced', len(bounced_addresses), tags={
                'domain': subevent.parent.domain,
            })
            subevent.error(
                MessagingEvent.ERROR_EMAIL_BOUNCED,
                additional_error_text=", ".join(bounced_addresses)
            )