Skip to content
Advertisement

sendgrid mail sending error upon placing multiple receiver

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: ["demo@email.com", "demo1@email.com"],
    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

Advertisement

Answer

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: "demo@email.com",
        name: "demo"
    },
    {
        email: "demo1@email.com",
        name: "demo"
    }
]

Assuming mailsTo is being pass as the to parameter for

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement