Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edgar Rasquin 326 posts 925 karma points
    Jun 15, 2023 @ 16:17
    Edgar Rasquin
    0

    uncheck the globally unsubscribed checkbox for a contact

    Hi Markus,

    I have the problem that I can't uncheck the globally unsubscribed checkbox for a contact when they re-subscribe to the newsletter. I use the following code:

    public bool Subscribe(SubscribeModel model)
        {
            var defaultMailingListKey = Guid.Parse("884E9084-26E6-411F-AD5A-0A0911075A19");
            var subscribers = _newsletterStudioService.GetRecipientsByEmail(model.Email);
    
            if (subscribers != null && subscribers.Any())
            {
                foreach (var subscriber in subscribers)
                {
                    subscriber.GlobalUnsubscribed = false;
    
                    var addRecipientRequest = new AddRecipientRequest(model.Email)
                        .WithFirstname(model.Firstname)
                        .WithLastname(model.Lastname)
                        .SubscribeTo(defaultMailingListKey);
    
                    var result = _newsletterStudioService.AddRecipient(addRecipientRequest);
    
                    if (result.Success)
                    {
                        return true;
                    }
                }
            }
            else
            {
                var addRecipientRequest = new AddRecipientRequest(model.Email)
                    .WithFirstname(model.Firstname)
                    .WithLastname(model.Lastname)
                    .SubscribeTo(defaultMailingListKey);
    
                var result = _newsletterStudioService.AddRecipient(addRecipientRequest);
    
                if (result.Success)
                {
                    return true;
                }
            }
    

    Can you tell me how to save the subscriber after I set subscriber.GlobalUnsubscribed = false;

    Or am I on the wrong track completely?

    Thanks

  • Markus Johansson 1911 posts 5757 karma points MVP c-trib
    Jun 21, 2023 @ 19:10
    Markus Johansson
    0

    Hi!

    I'm wondering what the "_newsletterStudioService.AddRecipient"-call in the first part of your if-statement returns? I mean you're basically trying to add a recipient that already exists right? Does it return true for result.Success?

    At the moment there is not a good way to set the GlobalUnsubscribed-property of the recipient in a programmatic way since we don't expose the store-method from our internal repository.

    I need to plan for some updates to the API to facilitate this. While you wait for this, maybe a simple SQL-statement to update the row in the db-table is a viable workaround?

    Also, may I ask which version of Umbraco and the package you're running on?

    Cheers!

Please Sign in or register to post replies

Write your reply to:

Draft