In firebase rule how to get an email notification to my own email when user submit dataFirebase rules.
From firebase rules side..
mail notification sent coding not done in the app
There is no way to trigger sending an email from Firebase security rules.
If you want to send an email when data is entered into the database, consider using a solution like Cloud Functions that can be triggered on such a database write operation. A similar (not same) scenario is shown in the example on notifying the user when something interesting happens.
Also see:
Send email when Firebase database gets new data
I want connect my firebase information with my mail
Send data from Realtime Database using Firebase Functions to email
Sending automated emails from Firebase through Google Cloud Platform (no third parties)
Related
Please note that this question is not about getting device token on client side.
I am very new to react-native and firebase and I want to implement push notication service of FCM. What I am planning to do is to send a notification to particular device using its device token on my nodejs app server or cloud function( not through console). But as I have found, FCM doesn't provides any API to accrss token by username. Suppose I want to send notification to user X( for the time being, suppose that one user signs only on single device). Now using the function sendToDevice(), I can send the message to a specific device. But how would I know the device token of user X. Do I need to store tokens in the firebase database by myself? Or can I get along without storing FCM tokens?
Please guide me because firebase docs aren't clear about this.
Save the device token for a particular user in DB and then you can use fcm-node npm in which there is a simple function to send a push to a particular device token.
You also need to use the FCM server key which you will get easily on the firebase console.
FCM doesn't offer a way to associate device tokens to individual users who might be using your app from multiple devices. You will need to write code to associate a device token to a user account by sending that token to your backend, along with the user's ID. Only then can you collect FCM tokens for that user, and message them on any of their devices.
How would i send a push notification automatically, instead of doing it through the firebase console manually. Like when user invites another user send a notification to the user that they have been invited. I am getting the user device token by doing firebase.messaging().getToken();
You would need to develop your own server where you need to save device token and send push notifications based on various triggers.
Alternate way - if you are using other Firebase services like Firestore - you can go with Firebase Functions. Here is quick overview: https://firebase.google.com/docs/functions/use-cases
Do it through your backend, First you need to register users' token on your backend and when userA send invitation to userB send that request to the backend and your backend should have userB token, it will send userB notification.
If you use firebase DB and want to send push notification by some actions (for example, new record in your db ), you can try to use firebase functions.
See here for more information
In any other ways - you should create your own server app that will be connected with fcm or apn services and your db. Of course, you should configure your server app correctly.
I am trying to create an android application and would like to use firebase database. As I read firebase allows instant messaging and also notify clients when database is updated. I need to create a database and when any database changes happen, related users needs to be notified only. Is that possible with firebase or should I use backend server for this purpose?
You can do it using the Firebase only.
What you needs are
Firebase Database (Realtime database/Firestore)
Firebase Cloud Functions
Firebase Cloud Messaging (FCM)
You should write two side codes:
Client side (Android)
Server side (Cloud Functions)
In Client side (Android)
You should register token. (To send a notification using the FCM, Token is needed.) You can do this easily (https://firebase.google.com/docs/cloud-messaging/android/client)
I recommend that you can store the token into the database/firestore too.
for example:
class User {
long id;
String email;
String token;
}
You may write the code to modify the database/firestore.
Implement receiving code (https://firebase.google.com/docs/cloud-messaging/android/receive)
In Server side (Cloud Functions)
Add some trigger to the database/firestore.
Get the token from the database/firestore
just send FCM message (https://firebase.google.com/docs/cloud-messaging/admin/send-messages)
You can get the sample code for Server side (Cloud Functions)
https://github.com/firebase/functions-samples/tree/master/fcm-notifications
Yes you can achieve this using Firebase Cloud Functions which:
lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment.
And with Firebase Cloud Messaging which:
Is a cross-platform messaging solution that lets you reliably deliver messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention.
So you can write a function in Firebase Cloud Functions which will trigger a notification every time something is changing in your database. Both documetations are very well explained.
I am trying to send the notification from one user to another user of the same app.
I am following this article : https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
Here it takes username and message. But the username is plain name, how it will identify the which device it needs to send the notifications.
Or it is firebase id: FirebaseInstanceId.getInstance().getToken()
Or I have to manage mapping of user to device on the server.
And what is FIREBASE_URL?
The article you read uses FCM topics to identify users. This is a naïve-but-simple way of addressing users. If your needs are more complex, you will need to manage your own mapping of users to tokens on your server.
For an example of using Cloud Functions to send FCM messages to tokens, see this sample in the Firebase documentation.
When users register with my application, I want my application to automatically send some verification code to user email. I will generate verification code, but i don't know how to automatically send it to user email.
Give me some solution guys!!
NOTE!!!!!!!
I am not asking how to send email to someone which is like choosing email app and it populates subject and body in the application.
Then you have to use web services. when user register with your app, you store user registration information in server database. while inserting user record in database insert verification code in one column. (write a code to generate verification code in web service it self.) after successful inserting row in database. you can easily pick email and verification code. Now you have all details of user. Write a code in web service to send verification code in email to user.
Normally its done from the server side. Generating authentication token and sending it to a mail address using an SMTP server. for example mail in php.
If you really want to do it on android side which doesnt open any application and directly sends a mail to gmail, here is an alternative I could find.
Sending Email in Android using JavaMail API without using the default/built-in app
firebase email verification is the best to verify the email without using any custom created service (API)