Developer forum

Forum » Development » GetRecipientContentContext in EmailRecipientProvider

GetRecipientContentContext in EmailRecipientProvider

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

I a trying to create av EmailRecipientProvider that adds som custom content to the emails. 

As I understand I should use the GetRecipientContentContext for this. 

Would this be the right way to populate a {{MyCustomTag}} in an email template? Propable not because I can't get it to work. :) 

        public override PageViewContext GetRecipientContentContext(Recipient recipient)
        {
            var pvc = new PageViewContext();
            pvc.SetValue("MyCustomTag", "MyCustomContent");            

            return pvc;
        }

Whats missing? Something with the recipient.RecipientKey?

Regards / Aki

 

 

 


Replies

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Aki,

In your provider you overrides GetRecipients() method.

Here, for each recipient you could set custom tags:

recipient.TagValueCollection.Add("MyCustomTag", "MyCustomContent");

Best regards,

Vladimir

Votes for this answer: 1
 
Aki Ruuskanen
Aki Ruuskanen
Reply

Hi Vladimir, 

Thanks. 

In my GetRecipiants() I have this now.  

            foreach (var user in userCollection)
            {
                var recipient = new Recipient
                {
                    EmailAddress = user.Email, 
                    Name = user.Name, 
                    RecipientKey = Convert.ToString(user.ID)
                };

                recipient.TagValueCollection.Add("MyCustomTag", "MyCustomContent");
                recipients.Add(recipient);
            }

What do I need to put in the GetRecipientContentContext() ? I need to implement it also.

Regards / Aki

 

 

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Aki,

Sorry, could you clarify why you need to implement GetRecipientContentContext()?

It is needed to store some additional data and then it could be used in razor renderer (@PageView.Context ).

You could put here any you want....

 

Best regards,

Vladimir

 
Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

Well I am required to be override it when I inherit from EmailRecipientProvider.

So I think it at least needs something like. 

            var pvc = new PageViewContext();            
            return pvc;

But I got everything to work now. 

Thanks for your help. yes

Regards / Aki

 

 

You must be logged in to post in the forum