Querying message bodies

To find a specific message body, you use the NewslettersManager class. The following code finds a message body with the specified Idthrough the Native API.

public MessageBody QueryMessageBody(Guid id)
{
    NewslettersManager manager = NewslettersManager.GetManager();
    MessageBody messageBody = manager.GetMessageBodies().Where(b => b.Id == id).SingleOrDefault();
 
    return messageBody;
}

First, you initialize the NewslettersManager. Then, you call GetMessageBodies to retrieve all message bodies and, finally, you filter the message bodies based on the Id property.

TIP: You can filter by any of the MessageBody properties.

Another way is to use the GetMessageBody method of the manager class:

public MessageBody QueryMessageBody(Guid id)
{
    NewslettersManager manager = NewslettersManager.GetManager();
    MessageBody messageBody = null;
 
    try
    {
        messageBody = manager.GetMessageBody(id);
    }
    catch (ItemNotFoundException e)
    {
        //implement logic regarding the missing item.
    }
 
    return messageBody;
}

NOTE: If no message body with the specified ID exists, the GetMessageBody method throwsTelerik.Sitefinity.SitefinityExceptions.ItemNotFoundException exception.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK