Home > database >  sendgrid mail sending error upon placing multiple receiver
sendgrid mail sending error upon placing multiple receiver

Time:08-17

I'm using const sgMail = require('@sendgrid/mail'); and utilizing sendgrid version 7.6.2.

When I'm adding two email addresses in array and passing that into send() or sendMultiple() it's throwing me error like this.

status: 'failed',
>    Error: Error: String expected for `email`

here's the section where I'm putting the multiple emails,

mailsTo = {
    email: ["[email protected]", "[email protected]"],
    name: "demo",
    type: 'to'
}

here if I pass one email as in form of string the mail is getting triggered. Can anyone please suggest what am I doing wrong.

Thanks in advance

CodePudding user response:

According to the documentation the addresses are to be passed as an array of EmailData (string or object with email and name).

Please try the following:

mailsTo = [
    {
        email: "[email protected]",
        name: "demo"
    },
    {
        email: "[email protected]",
        name: "demo"
    }
]

Assuming mailsTo is being pass as the to parameter for

  • Related