How can I verify email with Firebase Auth?

When a user creates an account with Email/Password I need my app to send an email to verify it.

I saw that on the Firebase Auth page there are templates for that (also for restore password and others), but how is it used? Or is there any other alternative? Like send a verification code or something.

Nope :melting_face:

Have you tried? It’s possible to connect your app to Google Apps Script, then send the email with Google Apps Script.

  • Generate a random integer with as many digits as you like. Save it in a variable.

  • Use the following code in Google Apps Script. Create the script in the account that you want to send the email as. Use GmailApp; EmailApp does not work with Gmail addresses.

function doGet(e) {
    var verificationCode = e.parameter.code;
    var address = e.parameter.address;
    GmailApp.sendEmail(address, "Verify your account", "This is the verification code for your account: " + verificationCode + ".";
    return ContentService.createTextOutput("Email sent." );
}
  • Deploy the web app as usual, remember to execute as your own Google account and make the script available to everyone, even those without a Google account. Copy the deployment URL.

  • To send the verification code, use a Web component with this URL and then use the Web.Get block.

1 Like

And the firebase auth templates?

@Gordon_Lu Wow! Very good answer. I didn’t know about the existence of Google Apps Script. I just tried what you said and it works:

Although I have a question. If I have a different domain, would I have access to Google Apps Script? For example, I want that instead of sending an email like “[email protected]” use my own domain, like “[email protected]”. Do you know if that is possible?

@Gordon_Lu, Google allow only 500 email per day

Where did you find this? This is not listed in the Google Apps Script quota limit. There is a limit for email size, but it doesn’t take up so much space.

I’m not sure. If you have a different domain, you might want to try changing GmailApp to MailApp?

1 Like

I’ll try it in the future, thanks!

Well, I was looking and MailApp has the function MailApp.getRemainingDailyQuota(), which returns an int with the value of remaining mails you can send.

For example:

function doGet(e) {
    var quota = MailApp.getRemainingDailyQuota();
    Logger.log("Remaining email quota: " + quota);
} 

This returned 500 to some people. In my case it returned 95 (I used it 5 times), so the limit would be 100 for me.

However, that function only exists in MailApp, not in GmailApp. Since yesterday I was looking for something similar for GmailApp and I didn’t find anything. I only found that the normal gmail daily sending limit is 500 (that is, sending emails normally, without using GoogleAppScript or something similar), I don’t know if it’s the same limit.

MailApp has this quota limit. Gmail does not. Read the previous posts.

I read the previous posts. In no post does it mention the difference in limits between GmailApp and MailApp, that’s why I wanted to mention it

1 Like