eladnava/mailgen

Improve flexibility of email contents

AlecRust opened this issue · 3 comments

The email contents values suit the three examples well, but are a little limiting if you're trying to create more generic emails.

The first thing I noticed on this was name being output after the language greeting (e.g. Hi). Perhaps this could just be title and allow the entire contents of this title to be managed in one value?

The second thing I noticed was the lack of flexibility with paragraphs. Mail contents need to fit within an action or table which may not suit simple emails with a few paragraphs. Supporting an array of paragraphs would be great, and perhaps a definition list for blocks like this:

screenshot

Hi @AlecRust,
These are excellent suggestions!

Regarding the title -- this should be easy enough to add:

var email = {
    body: {
        title: 'Your Monthly Report' // this will override "{greeting} {name}" in the templates if specified
   }
};

We do want to keep supporting the existing users of Mailgen and I do think that it's still practical to simply pass in a name, so I think it should still be possible to use the name and greeting keys.

Regarding the paragraphs -- good point. I'm thinking that intro and outro can become arrays (strings will still work) and the templates will traverse them, inserting line breaks in between them or wrapping them in <p> tags, depending on the template.

var email = {
    body: {
        intro: ['Welcome to Mailgen!', 'We\'re glad you joined us.'],
        outro: 'We hope you enjoy the package!'
   }
};

And finally, regarding the blocks, should be pretty easy to implement as an additional property for body, possibly named data:

var email = {
    body: {
        intro: ['Welcome to Mailgen!', 'Here are your account details:'],
        data: {
                    name: 'Mr Test',
                    email: 'mrtest@test.com',
                    telephone: '0123456789',
        }
        outro: 'We hope you enjoy the package!'
   }
};

I think data is a bit ambiguous, would love to hear a better name for this.

Let me know what you think, and also if you'd like to help with this (if not, that's okay). =)

Sounds good to me. I'd probably go with definitionList if that's the HTML that will be output.

Happy to take a look at this, might not get to it for a few days though.

@AlecRust cool, let me know if you have any questions. I think dictionary might be more appropriate (as those are key-value pairs).