leemunroe / grunt-email-workflow

A Grunt workflow for designing and testing responsive HTML email templates with SCSS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Info needed

Cre8tiveDigital opened this issue · comments

Hi, I was just wondering did you or anyone ever get the grunt mailgun task to send out more than one email test if there are multiple folders containing emails?

Thanks

@Cre8tiveDigital I haven't personally looked into this but I imagine adding some task to this Mailgun file that finds all templates in a folder and loops through them.

grunt send --folder=transactional or similar.

commented

@Cre8tiveDigital - Here's an example how you'd do it.

Create the file /grunt/massmail.js with the following code:

// Massmail
module.exports = function(grunt) {
    grunt.registerTask('massmail', 'Send bunches of email, quickly ✌🏽.', () => {
        const { dist } = grunt.config.get('paths');

        // Allow matching pattern via --pattern="", default to all (*)
        const pattern = grunt.option('pattern') || '*';

        // Get and loop .html files matching the given pattern in /dist
        const files = grunt.file.expand(`${dist}/${pattern}.html`);

        files.forEach((filepath) => {
            const filename = filepath.split('/').pop();
            grunt.option('template', filename);
            grunt.task.run('mailgun');
        });
    });
};

Then you can just run grunt massmail --pattern="somefolder/*"
The --pattern option allows you to get as clever as you want and will match all .html files with that pattern. WARNING the sample code will send all templates in the root /dist folder by default.

commented

@Cre8tiveDigital - Did you ever give this a go or come up with an alternate solution?