Moralis is not sending email verification to users

I have followed the email sign up, and send email tutorial, and now the user can login and receive emails, however Moralis is not sending the verification email to them, so the emailverified is always empty.

Email send by using a function I’ve coded

The flag Will never change as the verification email is not being sent

Hi,

Could you please share your cloud function code where you were sending email verifications.

Thanks.

A.Malik :slight_smile:

Actually I thought that every time a user is created using email signup Moralis would sent a email verification to them. I just tried a normal email like this (and worked as regular email):

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

It is working, but I do not know how to send an email with a link (which will modify the emailVerified field). Do you have any example or tutorial about it?

1 Like

Hey @infinity

Unfortunately, I can’t test this now, but it looks like your email message is sending as HTML, so try to use:

Moralis.Cloud.define("sendEmail", function (request) {
    Moralis.Cloud.sendEmail({
        to: request.params.email,
        subject: "Fundamentals",
        html: "<html>Pampamentally it does make sense 
                  <a href='https://youtu.be/xXrkgWDcd7c'>Link Name</a></html>" 
    });
});

Let me know how it works.

Thanks for your answer. The issue is not sending an email. The issue is verify an email. How can I properly verify an email and change the emailVerified field on the database?

Do you use React or Vanilla JS?

Could you please share code you use to register new users.

No. I’m using javacript only.
image

Moralis is not sending email to user as it is described on the image,

Try to use the function bellow:

await Moralis.User.requestEmailVerification();

Let me know how it works.

It is not working! Is it working for you?

Hello,

Unfortunately, I can’t test this now, because my StillGrid account still isn’t ready. But I will send you a solution ASAP. :slightly_smiling_face:

Hey man, any updates?

1 Like

Hi,

does anyone have an example on how to send the verification email? Thanks

You can do it this way.

sendEmailVerification = async () => {
        let user = Moralis.User.current(); // delete this if setted globaly
        let userEmail = user.attributes.email;
        await Moralis.User.requestEmailVerification(email)
          .then(() => {
            //user will get an email with a link. If the user clicks on the link his user get authenticated.
            console.log("Successfully sent email verification email");
          })
          .catch((error) => {
            // Show the error message somewhere
            alert("Error: " + error.code + " " + error.message);
          });
      };

Also, check out the docs over here for more email authentication states. –

https://docs.moralis.io/moralis-server/users/email-login#verifying-emails

Hope this helps.

Happy BUIDLing! :man_mechanic:

2 Likes

Thanks, that works! Email was sent.

Do you know also how to do the verification itself? Where do I get the link for verification, …?

The verification is handled by Moralis itself. The link will be unique for each email being sent and will be embedded in the email. You need not manually work on it.

Happy BUIDLing !

1 Like

@malik you guys should update the documentation to include that requestEmailVerification needs to be explicitly called. From the docs, it seems like it says that the verification email will automatically be sent after calling signUp

Also, it seems that for people using webhooks like myself, the requestVerificationEmail function is not present in moralis/node:

Is there a chance this can be fixed? It’d be great that emails get automatically sent every time the user email field changes.

@acorredor, what version of Moralis you have there?