Тёмный

Using Flask-Mail to Send Email Confirmation Links 

Pretty Printed
Подписаться 96 тыс.
Просмотров 39 тыс.
50% 1

This video demonstrates how to generate and send email confirmation links using Flask-Mail and itsdangerous in web apps.
WORK WITH ME👇🏼
✅ Implement features and fix bugs in your app: Live, one-on-one screenshare
prettyprinted....
💻 Code written in video
prettyprinted....
Join my free course on the basics of Flask-SQLAlchemy: prettyprinted....
Get the Flask cheat sheet: prettyprinted....

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 106   
@prettyprinted
@prettyprinted 4 года назад
Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql
@quechon1
@quechon1 7 лет назад
Man people can build a whole web app just by watching this channel keep it up.
@prettyprinted
@prettyprinted 7 лет назад
Yep, that's the idea. Thanks for watching.
@sinabooeshaghi5919
@sinabooeshaghi5919 6 лет назад
Dude you make such amazing videos! I am a self taught programmer and your explanations are so clearly laid out and thorough I 100% appreciate it. I am working on my first webapp now with Flask and I have made so much progress thanks to you. Thank you again and keep on making great vids!
@prettyprinted
@prettyprinted 6 лет назад
Glad I could help.
@oppzreq9707
@oppzreq9707 Год назад
Wow, this was one of the most straight forward tutorials ever! Thank you so much!
@evanwallace2658
@evanwallace2658 3 года назад
Amazing video! Your style of teaching is great! Easy to understand, quick, and to the point. Thank you so much!
@ValeriiPavlikov
@ValeriiPavlikov 6 лет назад
I don't speak much english but I want say to u THANK U VERY VERY MUCH! Your tutorials are useful for me!
@prettyprinted
@prettyprinted 6 лет назад
you're welcome!
@olegpyzh
@olegpyzh 2 года назад
Thank you! This video helped me a lot! I was stuck on Email sending for a while: I was using Gmail and found out that "Less secure app access" was no longer available, so I switched to Zoho email and it finally worked well.
@dr.shaimaahamada2477
@dr.shaimaahamada2477 Год назад
for solution of this problem there is a section called App passwords and when you generate a new password and use it as your email password it takes the place of "Less secure app access" and the error goes.
@guershondorismond271
@guershondorismond271 5 лет назад
Your are really good at what you do. This helped me integrate email validation with my flask python. Without the usual rabbit hole of issues that I run into. I really appreciate the video. Keep up the great work!
@prettyprinted
@prettyprinted 5 лет назад
Glad I could help! Thanks for watching!
@handelsassistentenundtradi2724
I learn a lot with your content. Great job!
@bispro89
@bispro89 7 лет назад
You made me stuck into Flask, not Php and CodeIgnite anymore. thanks.
@prettyprinted
@prettyprinted 7 лет назад
Haha didn't know I had that effect on people.
@kwhandy
@kwhandy 6 лет назад
wahahaha
@vatsalaykhobragade
@vatsalaykhobragade 5 лет назад
@George hatouts yeah (:
@Woody_Clayton
@Woody_Clayton 6 лет назад
You made my day! Thanks
@prettyprinted
@prettyprinted 6 лет назад
You're welcome!
@handelsassistentenundtradi2724
Once again a helpful video. Thank you. I ran in some difficulties, because I used views in my project and encountered the circular import problem. With current_app.app_context() I managed to get the sending of the mails working.
@eugeneodonnell9749
@eugeneodonnell9749 7 лет назад
A very clear tutorial on a useful topic
@prettyprinted
@prettyprinted 7 лет назад
Thanks for watching!
@peralser
@peralser Год назад
Amazing Video!!! Thanks for sharing it.
@WannaSeeWhatYouGot
@WannaSeeWhatYouGot 6 лет назад
Great tutorial, and no dislikes prove that!
@verygood5377
@verygood5377 4 года назад
Great video again. Learn a lot from this channel !!
@amirsinah
@amirsinah 2 года назад
Awesome video. Thanks!
@artemkhmil
@artemkhmil 3 года назад
Thanks a ton for such cool video!! Very useful! Great job!
@huzeyfast
@huzeyfast 3 года назад
Very helpful video, thank you
@jisgerald8723
@jisgerald8723 4 года назад
Thanks a lot!! This worked for me 100%
@shardulkulkarni1008
@shardulkulkarni1008 4 года назад
great work dude!!! thanks for your video.
@indahpratiwi4308
@indahpratiwi4308 5 лет назад
Thank you for making this video
@prettyprinted
@prettyprinted 5 лет назад
You're welcome! Thank you for watching.
@KieuTranVan
@KieuTranVan 7 лет назад
Very useful video! Thanks!
@prettyprinted
@prettyprinted 7 лет назад
You're welcome. Thanks for watching!
@abbysands9510
@abbysands9510 3 года назад
itsdangerous is a very good module for validating tokens but there is one major problem. As long as the token has not expired the user can validate the token over and over again. Let me give you an example. Suppose you create a token that expires in 24 hours, as long as the token is less than 24 hours old the user is able to validate the link over and over again which is not what you want. You want them to use it only once and then if they did click on it again nothing happens, maybe you can have a message stating that you have already used the token. The way I get around it is to create a field in the database called token. When I issue the token to a user I store that token in the database after the user has validated their token I set that field to none. Now when the user clicks on the token the database is called before itsdangerous function if the field is none a message displays saying to the user that there is no token to validate.
@mpt912
@mpt912 7 лет назад
Hey Anthony, quality content as usual! I actually implemented this during the weekend, could have used your video then, but luckily I managed anyway! As a follow-up question, since I couldn't find a way to expire the token manually when a link has been clicked, I set up a table for each token which I then set to used=True after a token has been used successfully. My gut tells me it would be cleaner to completely delete the token from the DB when it's been used, but then I can't come up with a solution how to tell if it's been used unless I actually query the database instead of comparing the token from the UrlSerializer of course... Come to think of it. Anyway! So far, so good. But I was wondering if a token could actually be generated identically twice, because that could eventually become an issue with password-resets etc for my current solution (just setting the token to used). Again, many thanks for your videos!
@prettyprinted
@prettyprinted 7 лет назад
Yeah, tokens can be generated twice. I recommend using salts for distinct scenarios, like registration vs. password reset. Instead of having the tokens in the database permanently, you could instead have an active token table. When a user registers, you can add the token into the same. When you go to verify, both the token has to be valid and it has to be in the active table. Once it's used, remove it from the active table. I'm sure there are other ways of approaching this (like always have a max age), but that was the first thing that came to mind.
@bispro89
@bispro89 7 лет назад
Great one.
@KhaiTienDo
@KhaiTienDo 9 месяцев назад
Thank you
@irmapreldzic1264
@irmapreldzic1264 2 года назад
Thank you for this! I have a question, is there a way to make this link only clickable once. Like a onetime link?
@FlexThoseMuscles
@FlexThoseMuscles 6 лет назад
Thanks a lot!!
@prettyprinted
@prettyprinted 6 лет назад
You're welcome. Thanks for watching!
@sanjayshr1921
@sanjayshr1921 7 лет назад
You're awesome :) Tutorial request: CRUD app with Flask + Vue JS 2 + Redis, please.
@prettyprinted
@prettyprinted 7 лет назад
Vue will probably be the next thing I cover after Vue. So combining the two seems natural.
@sanjayshr1921
@sanjayshr1921 7 лет назад
Ok
@jasonchu852
@jasonchu852 4 года назад
thanks! very useful ! ! !
@Anshegar
@Anshegar 5 лет назад
ERROR: smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server. (all data from mail server i put in code, but not works)
@fun2badult
@fun2badult 4 года назад
I'm getting the same error. I think google might have changed the authentication or something
@fun2badult
@fun2badult 4 года назад
Ok I solved the issue. This is for Gmail. You need to go to Google Account Settings and under Security, then scroll to the bottom where it says 'Less Secure App Access' and turn this on. This will allow the app to access the gmail. Then turn it off after
@premier03lin30
@premier03lin30 4 года назад
Hi may I have the configuration for gmail? Thanks :)
@shouyudu936
@shouyudu936 3 года назад
app.config['MAIL_SERVER'] = 'smtp.gmail.com' app.config['MAIL_PORT'] = 587 # for security app.config['MAIL_USE_TLS'] = True app.config['MAIL_USE_SSL'] = False
@shouyudu936
@shouyudu936 3 года назад
Note: you need to lower down your google login security in the setting
@shivamkapoor1827
@shivamkapoor1827 5 лет назад
Please also make video on password reset email and also tell what is the difference between UrlSafeTimedSerializer and TimedJSONWebSignatureSerializer of itsdangerous package
@prettyprinted
@prettyprinted 5 лет назад
Thanks for the ideas. I'll consider making videos on those topics.
@gurdeepsingh503
@gurdeepsingh503 6 лет назад
how can i get mail server for my gmail?
@gurdeepsingh503
@gurdeepsingh503 6 лет назад
ok i get it smtp.gmail.com... and thanks code works
@TheChendoBeats
@TheChendoBeats 4 года назад
Can I add this to my Flask Log-In app???
@sathishkrishnan8273
@sathishkrishnan8273 2 года назад
I tried sending mail with this statement command MAIL_USE_TLS=False but its not working. After removing this statement I'm able to send mails without any errors.
@prashantpokhriyal6308
@prashantpokhriyal6308 4 года назад
I am facing ' NameError: name 'SignatureExpired' is not defined ' during try except SignatureExpired
@ashjan6027
@ashjan6027 3 года назад
getting an error TypeError: Object of type set is not JSON serializable. Can you pls advise.
@mirzag7099
@mirzag7099 4 года назад
error a rah yeh how to solve werkzeug.routing.BuildError: Could not build url for endpoint 'confirm_email' with values ['token']. Did you mean 'contact' instead?
@leisureclub_
@leisureclub_ 6 лет назад
I got this Error while running script and then going to the Browser... socket.gaierror gaierror: [Errno 11001] getaddrinfo failed Can you please tell me what i should add there?
@mamidilokesh1571
@mamidilokesh1571 5 лет назад
Even I got this type of error, did you find any solution?
@yousifshalby3421
@yousifshalby3421 4 года назад
@@mamidilokesh1571 did you solve it ?
@mamidilokesh1571
@mamidilokesh1571 4 года назад
@@yousifshalby3421 in most of the cases If you are using public WiFi then it will be blocked. I tried with my mobile hotspot then it worked
@shivamkapoor1827
@shivamkapoor1827 5 лет назад
Hay your cheat sheet have some mistake in jason response u directly import jsonify but it is from flask import jsonify this cause lot of problem to me to figure out the error in my program and waste my time too please correct it
@prettyprinted
@prettyprinted 5 лет назад
Thanks for letting me know. I'll fix it.
@lorenzopinto3887
@lorenzopinto3887 5 лет назад
Thank you for the video! Unfortunately the link with the code returns 404, can you fix it? Thank you again!
@prettyprinted
@prettyprinted 5 лет назад
Thanks for letting me know. Here's the new link: prettyprinted.com/l/Fbw
@kwach4566
@kwach4566 5 лет назад
thanks
@prettyprinted
@prettyprinted 5 лет назад
You're welcome!
@ramroshan417
@ramroshan417 6 лет назад
I am sorry, but how to get the name/IP address and the port of your mail id (to type in the configuration file)? Or should we create an account? Did not get that part. Can you (or someone) please tell me what exactly to type in the config.py file and where to get the details ('cause I am getting a Connection Refused error)?
@prettyprinted
@prettyprinted 6 лет назад
It depends on the mail provider you use. There should be documents you can look up to get the info.
@ikennaudokporo6061
@ikennaudokporo6061 7 лет назад
you said something about sharing the link for email configuration... can't see it
@prettyprinted
@prettyprinted 7 лет назад
prettyprinted.com/blog/577542/using-flask-mail-to-send-email-confirmation-links
@sarath_sajan
@sarath_sajan 4 года назад
@@prettyprinted it's a 404
@blakeharris9868
@blakeharris9868 7 лет назад
when it hits the confirm email link, how do you associate that with a user? basically how should one look up a user based on the url with just a token?
@prettyprinted
@prettyprinted 7 лет назад
One way is to just use the email in the video. email = s.loads... will return the email address used to create the token.
@blakeharris9868
@blakeharris9868 7 лет назад
Ah i see, would you recommend keeping a table of tokens and users?
@prettyprinted
@prettyprinted 7 лет назад
If you're only validating email addresses, then no, storing them is not necessary. If you're using tokens for something like session handling, then you'll have to store them.
@mamidilokesh1571
@mamidilokesh1571 5 лет назад
The following type of error is showing, could you please help me out? and How can we find out mail server name? TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
@prettyprinted
@prettyprinted 5 лет назад
Your computer couldn't connect to your mail host. Make sure that your credentials are correct and that your mail host allows remote connections.
@tchen921
@tchen921 6 лет назад
Hi, what if I put the flask-webapp onto an actual server? I put it on AWS EC2, configured with nginx, and it runs inernally at 127.0.0.1:8000 so the confirmation email link is still starts with local address 127.0.0.0.. :(
@tchen921
@tchen921 6 лет назад
my solution, I hardcoded the public ip of my ec2 instance to replace the '127.0.0.1:8000' in the confirmation link.... I guess there should be a more intelligent way to do it...
@prettyprinted
@prettyprinted 6 лет назад
Well when your app is actually being used, wouldn't you use an actual domain name instead of an IP address? In that case, you'll have to provide your domain name some where. Look into the SERVER_NAME config variable as well: flask.pocoo.org/docs/0.12/config/
@brettvanderwerff6917
@brettvanderwerff6917 5 лет назад
Is it safe to use the same logic to generate a link for users to reset their password?
@prettyprinted
@prettyprinted 5 лет назад
Yep, it's pretty much the same process.
@brettvanderwerff6917
@brettvanderwerff6917 5 лет назад
@@prettyprinted great. Thanks for making the videos. I'm a hobbyist and have honestly watching them for a year or so. You have a clear approach to it.
@sarveshrayter7667
@sarveshrayter7667 5 лет назад
hey guys i am a beginner but can u tell me from where can i get all the mail configuration settings of mine? thanks in advance
@prettyprinted
@prettyprinted 5 лет назад
What email provider do you use?
@sarveshrayter7667
@sarveshrayter7667 5 лет назад
Hey, thanks for the concern .. solved the problem. :)
@PavanKalyan-py5vi
@PavanKalyan-py5vi 5 лет назад
@@prettyprinted gmail
@PavanKalyan-py5vi
@PavanKalyan-py5vi 5 лет назад
Hi i am a beginner can you solve me this error socket.gaierror socket.gaierror: [Errno -2] Name or service not known at the end it says socket.gaierror: [Errno -2] Name or service not known
@fun2badult
@fun2badult 4 года назад
you need to put up the code for people to see what you've done wrong
@anubhavkumaryt
@anubhavkumaryt 5 лет назад
hey, i want to send an attachment with my email, how do i do that?
@prettyprinted
@prettyprinted 5 лет назад
Look up my videos on Flask-Mail.
@ramroshan417
@ramroshan417 6 лет назад
If I run the code when the Internet connection is off, I get a "socket.gaierror: [Errno -3] Temporary failure in name resolution' error. Can (or anyone else) you please tell me how to catch this exception and display something like "Make sure you are connected to the Internet" or something instead?
@prettyprinted
@prettyprinted 6 лет назад
I don't know what the exact exception name would be, but you can use a try/except around the relevant code and return your error message in the except block.
@ramroshan417
@ramroshan417 6 лет назад
Yeah, I figured it out. This worked: except socket.gaierror as e: blah blah... JIC someone else ends up with the same problem. Thanks for replying, though. :)
@prettyprinted
@prettyprinted 6 лет назад
Glad you figured it out.
@marygaewu200
@marygaewu200 4 года назад
good content. but can Kindly work on the quality of the video. I managed it anyway..thanks!
@christianbarnes8963
@christianbarnes8963 5 лет назад
please how do i import mail so i can send in another file
@prettyprinted
@prettyprinted 5 лет назад
You input the mail object from where ever you instantiated it.
@christianbarnes8963
@christianbarnes8963 5 лет назад
@@prettyprinted i try to get from g but i keep getting connection problems
Далее
Using Flask-Mail to Send Emails in Flask
40:05
Просмотров 35 тыс.
Women’s Celebrations + Men’s 😮‍💨
00:20
НЕ БУДИТЕ КОТЯТ#cat
00:21
Просмотров 1 млн
Sending Email using Python in 5 statements
9:53
Просмотров 232 тыс.
Sending Email From Web Forms - Python and Flask #6
7:31
Sending Emails in Flask Apps
8:29
Просмотров 22 тыс.
I Remade YouTube From Scratch Using Just Bash
17:51
Просмотров 23 тыс.
Intro to Flask-Security
22:49
Просмотров 39 тыс.
How to Send Emails with Flask Using Python
9:10
Просмотров 25 тыс.