I am new to firebase and I am trying to handle firebase user authentication in React.js. I did manage to create users with email and passwords. But, now I would like to send the user an Email link to reset their password.
My code currently look like this.
// This line of code belongs to the top
import { auth } from '../firebaseConfig'
//This part goes under the React component
<p onClick={async () => {
try{
await sendPasswordResetEmail(auth, // My Email Id)
alert('Password reset link has been sent to your email')
}
catch(err){
alert(err)
}
}}
>Forgot your Password ?</p>
However, I do not get any error messages and I do get the alert message that says "Password reset link has been sent to your email." Unfortunately, I didn't receive any email. Note that I have given my own email id as the parameter for testing purposes.
firebaser here
Did you check your spam folder? We recently see a lot of the emails from Firebase Authentication ending up in the user's spam folder or being marked as spam in a system along the way. This is being tracked in this status message on the Firebase dashboard and in public issue #253291461.
To reduce the chances of the messages getting marked as spam, consider taking more control of the email delivery yourself.
As a first step, consider using a custom domain with your project. Email that comes from a custom domain has less chance of being marked as span.
As a second step, consider setting up your own SMTP server.) for delivering the email, so that the emails are not being delivered from Firebase's shared infrastructure anymore.
While these steps are more involved, they typically will drastically reduce the cases where the messages from Firebase Authentication are marked as spam.
Full Guide Based on Frank's Answer
Firstly create a new email account you can use to relay the Firebase emails through the SMTP server with. I personally chose Gmail, but I tested with Outlook and it also works.
You can now find an SMTP server host that will work for your scenario. If you're sending less than 1000 emails per month you can find free and reliable hosts. I chose SMTP2GO's free option.
Now you've found the SMTP host, add the email address you've chosen as a single sender email (note that if you do own a domain, you can alternatively use that to send emails).
Note that you will have to verify the email, usually by your host sending a link to the email's inbox. Make sure to check spam.
Once verified, navigate to where you host allows you to add SMTP Users and add a new user. This will allocate an SMTP username and password.
Navigate to the Firebase console, and choose the Authentication option from the sidebar (within the Build product category).
Go to Templates → SMTP Settings and enter the details of your SMTP server. The username and password fields are to be filled with the SMTP user login you created in the step above.
It is better to use TLS, but I believe SSL should work too but it is untested.
Click save, and you're all set up - but there may still be steps to perform depending on your email provider.
Provider Specific Steps
If the emails are being sent to an account managed by Google you will have no issues with your emails being quarantined by anti-spam policies and it will work immediately.
If you are using Outlook, you will have a different problem on your hands. Outlook's built in defender will most likely have auto-quarantined your email under multiple policies - that bit is important.
These policies are likely to be both spam and phish policies. If you unblock one of them, the other will catch it and re-quarantine.
Unblock both policies for the email address, and test. You can see the status of quarantined messages in Microsoft 365 Defender app under Review → Quarantine. Please note that you will need to be an administrator to add global allow policies to your email accounts.
If this still doesn't work it is likely that your company has an additional external filter (as mine did), and you will have to add the IP's manually to the Tenant Allow/Block Lists spoofed senders tab.
Related
I have a Java program utilizing the Gmail API that authenticates with our G Suite via OAuth 2.0, downloads all attachments for messages in a specific user's inbox, and processes said attachments.
I am experiencing a very specific issue where for some messages sent from certain fax servers that are being forwarded to the account, where the "to:" field is addressed to something other than the account itself, using
service.users().messages().get(userID, messageID).execute();
will not retrieve these attachments. This is even true if I am using the universal "me" identifier.
If I forward the message to myself and the "to:" field changes, the program is able to pick up on it, but not if it is addressed to someone else. This is a problem because these messages are addressed to an email that is outside of our G Suite domain. I have tried all methods of forwarding and filtering within Gmail, including forwarding to another provider like Yahoo, but automatic forwarding does not change the "to:"/deliveredto: field in the original email, and thus causes the same issue.
I have tried using a different method for authenticating, where I tried utilizing a Service Account for domain-wide delegation with the full Gmail scope, as referenced here Gmail API domain-wide delegation and following the exact steps outlined by the Google documentation.
The problem is, even when I use domain-wide delegation and specify the setServiceAccountUser as the fax user from the "to:" field, it says that is not a valid user, which makes sense as that is not a Gmail user or user within our domain, it is being forwarded from an external source we have no control over.
I have attempted to build a program that manually forwards these emails back to this platform account, but I run across the same issues as the service.users().messages().get(userID, messageID) method requires a userID and messageID.
Message message = service.users().messages().get("xxxxxxxxx#faxmail.vonage.com", messageID).execute();
Above is the section of code I've isolated where the .get() method is not allowing the program to get attachments for this external user, which seems to be directly defined by the "to:" field in the email - if I forward this email to myself and the "to:" changes to my user, it instantly is able to grab the attachment.
When I tried domain-wide delegation with a Service Account or changing the userID in the detailed method to the faxmail.vonage.com address, it would give me a 403 or 400 error - either complaining the user doesn't exist, or saying "Delegation denied for platform#xxxxxx.com"
If you are using G Suite you can use the Forwarding rules in the Control Panel to send all the emails coming for that address to whenever you want.
edit:
With the content compliance rules on the G Suite Admin Panel you can adjust the envelope information allowing you to change the "to" field.
Not a duplicate
I want to sent email without using any default email app so I searched a little bit and I stumbled upon this solution using JavaMail API -
Sending Email in Android using JavaMail API without using the default/built-in app
But I have few issues with this solution -
I don't want to use static username and password. Instead of that I want to use user's email ID. But it'll not be a good design if I directly ask user to enter his or her password.
So, how can I achieve this in a better way. Sorry, if this sounds too broad. Just looking for ideas not actual code.
Please, take a look at the Gmail API Android Quickstart guide. You'll be able to get the account credentials from Google Play Services and authenticate your user with OAuth2 by prompting an account selection
Instead of that I want to use user's email ID
As Gabe indicated, there is no "user's email ID" in Android. Beyond that, an "email ID" is insufficient for sending an email. You would have to ask the user both for all their email account information (username, password, SMTP server, etc.). Unless you are writing a full email client, hopefully nobody will give you this information.
how can I achieve this in a better way
Use ACTION_SEND or ACTION_SENDTO.
Or, send the email from your Web server, where your app tells the Web server what message to send via a Web service API that you implement and adequately secure. Then, you can use your own email account credentials without having to bake them into the app.
I have just started using mailgun. I am facing an issue. Lets say my domain is test,I have done this
abc#gmail.com--> support#test.mailgun.org --> myAccount#gmail.com
SO I am able to route incoming msgs coming to my gmail account, Now I want if I reply from gmail account to the particular user it should appear like that it is sent from support#test.mailgun.org.
myAccount#gmail.com --> abc#gmailc.com (appeared as it is sent from support#test.mailgun.org)
is it possible????
Language:- Java
Thanx to #Andersen, I got the solution. In gmail we have option in which we can change our mail id and make it look like it is coming from some different id while replying.
1) Go to settings in gmail
2) Click on Accounts
3) Send mail as: Click on Add another email address you own
4) Provide the email id you wish to appear as "Sender ID"
5) provide SMTP connection details which you can see once you login to your mailgun account and click on domain.
6) Save the settings, now when you are replying we can change from id to our custom domain id.
Enjoy
You need something to make the message leave your gmail inbox.
This can either be a rule in gmail itself (been a while, do not know what forwarding rules they have at the moment) or to use a client that reads a mailbox and resend the messages.
This is what the Unix utility fetchmail does, but you can easily use the java mail package to access gmail using IMAP and then create new messages based on these which you then send though your own SMTP server.
If at all possible use existing code! This is a bit tricky to get 100% right.
i have requirement that i need to send/receive email after successful login by user, upon click on email verification i will activate the user . i dont have dedicated smtp server for send/receive mails for this requirement. right now i am looking for free service for initial start up options , i gone through this http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ for sending email through gmail. my question is can i receive mail using gmail smtp service?
Short answer: No, not with SMTP. But probably with IMAP/POP.
Long answer: SMTP is only used for sending email between MTAs (Mail Transfer Agent). You'll have to download the email from your email provider, google in this case, using IMAP or POP.
You'll have to connect and check regularly as without an MTA service on your end, you can't get email pushed to you. Most personal ISPs block outbound port 25 so setting up a MTA might be tricky as you have to figure out your providers SMTP relay (if they even have one!)
See here for enabling IMAP/POP support for gmail:
https://support.google.com/mail/troubleshooter/1668960?hl=en
Google will find you a suitable imap/pop client library to use with java.
Edit:
If you are doing a regular e-mail verification step for a website registration, you don't need to receive an e-mail from the user. You send them an e-mail with a a link to your websites verification URL. The link contains a predetermined ID, say the sha1 sum of username + e-mail encoded into the URL. The user clicks the link and opens a specific page on your site where you verify the ID when the page is loaded. This is how it is usually done. This way you don't need to receive any email programmatically.
Unless receiving it by email is a specific requirement from your customer, in which case you can ignore this edit. :)
I have designed a chat application where different users can create the account, but I do not know how to send a confirmation email to the users. Since I collect their e-mail address in the registration form, how can I send mail to those addresses in Java?
First of all, you need a SMTP server. It's required to be able to send emails. You can make use of the SMTP server associated with your own existing email account, such as the one from your ISP or public mailboxes like Gmail, Yahoo, etc. You can find SMTP connection details at their documentation. You usually just need to know the hostname and the port number. The login details are just the same as from your email account.
You're however restricted to using your own address in the From field of the email and usually also in the amount of emails you're allowed to send at certain intervals. If you'd like to get around this, then you need to install your own SMTP server, for example Apache James, which is Java based, or Microsoft Exchange and so on.
Then, to send an email using Java code, you would need the JavaMail API or the more convenienced Apache Commons Email.
This looks like a good site for you: http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
Google 'send mail java'
The easiest way of doing this really depends on the environment that your JVM is running in.
If you're running in a standard Linux/UNIX environment and don't want to faff about with extra libraries, then one way is just to "manually" call sendmail (e.g. via ProcessBuilder). As with executing commands generally, you just need to be slightly careful that you don't just pass user input as parameters without screening them.