SendGrid Mail issue

Hello

I am trying to send mail using sendgrid & Moralis cloud functions
Cloud function is triggered but mail is not sent.

Can you help me?

Logs and code are as follows.

Cloud Function;

Moralis.Cloud.define("sendEmailToUser", function (request) {
  logger.info(request.params.email);
  Moralis.Cloud.sendEmail({
    to: request.params.email,
    templateId: "d-af62eea4a96e477b8c06316c80c601b7"
  });
});

Client Code;

async function subscribe () {
    const email = document.getElementById('semail').value
    await Moralis.Cloud.run("sendEmailToUser",{email,name});
}

Logs

2022-02-26T11:38:27.796Z - Ran cloud function sendEmailToUser for user b0yiBh4w6KfOTDpbvS8gCff3 with:
Input: {“email”:“redacted”,“name”:""}
Result: undefined

did you look in spam folder, did you add your Sendgrid api key in settings?

Hi,

Yes I added api key,
Also, I have tried it with both temp mail and my own mail. It’s not in the spam folder either.

1 Like

it looks like this syntax worked for me in the past:

   Moralis.Cloud.sendEmail({
    to: "[email protected]",
    subject: "test_message",
    html: "this is the body of the email"
  });

Just as a note to others finding this post: I encountered an issue with SendGrid not sending emails and it was caused by not setting the correct From Email in Moralis settings that matches the verified address in Sendgrid.

So that has to match what is set up in Settings> Sender Authentication (https://app.sendgrid.com/settings/sender_auth)


Either the Single Sender or Domain has to be Verified, or SendGrid won’t send anything.

1 Like