Building an email with content from the database

Hi there,
I’m trying to generate an email (or a file that can be emailed) with a fairly complex structure. I had intended to build up a string with this content in it, but can’t see a way to do it.

I have three database entities:

Requirements Document
User Stories

Each of these relationships is 1 to many (ie 1 document has many features, each feature has many stories).

I want to send an email for any given document, that lists its features, and then for each feature lists its stories.

For example:
Requirements Document 1
has the following features:

  • Feature 1
  • Feature 2

Feature 1
has the following stories

  • Story 1

Feature 2
has the following stories

  • Story 2
  • Story 3
  • Story 4

My App so far is available here:

Thank you!