Sign in
Log inSign up

nodemailer multiple recipients different context

Argjend's photo
Argjend
·Aug 3, 2016

I am trying to implement a method to send emails to multiple recipients but also I want to pass to the html template the user attribute which will have the name of the recipient.

My code in this stage is like this:

 SellerMatched: function (fromUser, offer, cb) {

        var maillist  = [];
        var users = [];

        for (var i=0; i<fromUser.length; i++)
        {
            maillist[i]=fromUser[i].email;
            users[i] = fromUser[i].Name;
        }


        maillist.toString();
        users.toString();



        mail.sendMail({
            from: 'Website Support <>',
            to: maillist,
            subject: 'Seller Matched',
            template: 'SellerMatch',
            context: {
                user: users,
                username: offer.owner.username,
                OfferName: offer.name,
                category: offer.category
            }
        }, cb);
    }

and the html have those attributes: It's something like this:

...

Hi {{user}},

A offer is uploaded that matched your preference. 
Offer detail:
Name : {{OfferName}}
By: {{username}}
Category: {{category}} 

....

This is working properly, emails are sent to the recipients but in the attribute Hi {{user}}, I want to show only the name of recipient because now it shows the array of all recipients.

Thanks

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct