Bad request while sending email using Moralid.Cloud.sendEmail

Hey,

I am trying to send an email with the following cloud code -



Moralis.Cloud.define("sendEmailToUser", async (request) => {
    const res = Moralis.Cloud.sendEmail({
      to: request.params.email,
      subject: "Fundamentals",
      html: "Pampamentally it does make sense https://youtu.be/xXrkgWDcd7c"
    });

    logger.info(`${res}`);

    return res
  });

I get this response

{
    "code": 141,
    "error": "Bad Request"
}

Please let me know how I can resolve this.

Thanks.

Hey @adityachakra16

I’m not sure if Moralis.Cloud.sendEmail returns something. Have you recieced your emails? I’ve tested and it worked correctly.

I haven’t received the emails. Here is the full log -

2021-08-10T16:23:48.692Z - Error: Bad Request
    at Request._callback (node_modules/@sendgrid/client/src/classes/client.js:124:25)
    at Request.self.callback (node_modules/request/request.js:185:22)
    at Request.emit (events.js:400:28)
    at Request.emit (domain.js:532:15)
    at Request.<anonymous> (node_modules/request/request.js:1161:10)
    at Request.emit (events.js:400:28)
    at Request.emit (domain.js:532:15)
    at IncomingMessage.<anonymous> (node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:519:28)
    at IncomingMessage.emit (events.js:412:35)
    at IncomingMessage.emit (domain.js:532:15)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)

Can sendEmail be used to send emails to any address? Or does the user’s email needs to exist in the user table?
Or in other words, what are the restrictions to sending emails using sendEmail when it wouldn’t work?

Which version of server do you use?

Currently the latest version is 0.0.247

Yes, I am on the latest version

You can send emails not only to addresses in the database.

Please send your server url

https://prdnf18aks9p.usemoralis.com:2053/server

The problem was solved by entering the correct address from

1 Like