简体   繁体   中英

Issue with firebase functions email sending

I am working on creating a button that when pressed, will send an email to a specific person (with their permission) through firebase cloud functions on my IOS swift app and am currently having a problem with the code that I am currently using. At the moment, I am trying to use this quickstart: https://github.com/firebase/functions-samples/tree/Node-8/quickstarts/email-users from these already created functions: https://github.com/firebase/functions-samples , and am trying to call the sendWelcomeEmail function. I plan on changing the code to send a custom message once I figure out how to get this to work instead of a welcome email. I have followed all the necessary steps including authenticating my google account and everything that is said needs to be done in the instructions, but when I run my code to call the function, and I print the error that comes up, I get:

Error Domain=com.firebase.functions Code=16 "UNAUTHENTICATED" UserInfo={NSLocalizedDescription=UNAUTHENTICATED}

I have looked up this error all over the internet, and nothing appears. There is literally no mention of this error, and I'm not sure if it's a problem with firebase, or the function and I am baffled as to how to proceed and get this working. The code that I am running to call this function is as follows:

Functions.functions().httpsCallable("sendWelcomeEmail").call(["email": "myEmail@gmail.com", "displayName": "myName"], completion: { (result, error) in
                if let error = error {
                    print(error)
                }
                return
            })

I would be perfectly happy using another function besides this one as well to send this email, but I do not know how to code Javascript and wouldn't know how to make one. If anyone has an answer as how to fix this, or an alternative to send a custom email to someone through firebase cloud functions, that would be great.

You're misunderstanding the sample code. The quickstart code you're linking to defines two Cloud Functions: sendWelcomeEmail and sendByeEmail . They are authentication triggers , and they trigger when a user creates an account and then deletes their account. This only happens when the app allows the user to create and delete their accounts with the Firebase Authentication API.

What you're trying to do is manually invoke one of these functions as if it's a callable function . But these are not "callable" functions. They are authentication triggers, and they've invoked automatically as the user manages their account. You can't simply invoke a background type trigger by using the Firebase SDK. If the only functions you can invoke directly with the Firebase SDK are callable functions .

So, what you're trying to do here will never work, because you don't have any callable functions. Please go over these documentation links again to understand the expectations for each of these types of functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM