How to Send Emails Using Python - Plain Text, Adding Attachments, HTML Emails, and More
In this Python Programming Tutorial, we will be learning how to send emails. We'll start with simple plain text emails and then learn how to construct more advanced messages. We will learn how to attach images, PDFs, create HTML messages, and more. Let's get started...
The code from this video can be found at:
bit.ly/python-emails
Google Account Settings:
myaccount.google.com/lesssecu...
myaccount.google.com/apppassw...
Environment Variables (Windows) - • Python Quick Tip: Hidi...
Environment Variables (Mac and Linux) - • Python Quick Tip: Hidi...
Lists Tutorial - • Python Tutorial for Be...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python
Пікірлер: 730
If you get hundreds of test email in your inbox, don't get disturbed! Be happy to know that hundreds of people implemented what they learned here... :) As always, Corey, you are one of the best in teaching python. Thanks for this contribution.
@cicerosilva-ye8mn
5 жыл бұрын
hey man Where am I wrong ?? my code = = = import os import smtplib from email.message import EmailMessage EMAIL_ADDRESS = os.environ.get('EMAIL_USER') EMAIL_PASSWORD = os.environ.get('EMAIL_PASS') msg = EmailMessage() msg['subject'] = 'teste de email' msg['from'] = 'anymail@gmail.com' msg['to'] = 'anymail@gmail.com' msg.set_content('teste de emial enviado pelo script em python') with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp: smtp.login(EMAIL_ADDRESS,EMAIL_PASSWORD) smtp.send_message(msg)
@motherfuqjohnson5460
4 жыл бұрын
@@cicerosilva-ye8mn what error? and what line is the error on?
@cicerosilva-ye8mn
4 жыл бұрын
@@motherfuqjohnson5460 in the sccrip ModuleNotFoundError: No module named 'email.message'; 'email' is not a package
@cicerosilva-ye8mn
4 жыл бұрын
at this from email.message import EmailMessage
@motherfuqjohnson5460
4 жыл бұрын
@@cicerosilva-ye8mn what IDE are you using? im using pycharm and i had to go into the interpreter settings to add the module. search up "how to add module to pycharm"
Thank you, for putting out a video of something so useful that many Pythonistas ask.
@av4787
4 жыл бұрын
Pythonistas
Your videos are my lifeline!! I am a retired programmer trying to learn Python. I've not used any other language apart from FoxPro since using Pascal 30 years ago.
As always, another great video chuck full of practical tips. I have never seen a video that you made that I felt was useless or poorly made. Your videos are always top notch and the best.
For anyone that had trouble, I changed my port number from 587 to 25 and it fixed the 'gaierror' for me. Also huge thanks to you Corey!! Awesome, streamlined content.
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. check out here: al-taie.github.io/quick-mailer
What I like about this is, eventhough the code is solid it didnt work untill I understood what I was doing. Thanks for that. That is a valuable lesson
thank you. you explained everything perfectly line by line and argument by argument
Your python tutorials are unfailingly amazing!
We need more people like you man!.
Corey, thank you very much for this video. It's extremely clear, fast pace, super useful. Thanks mate!
Thanks so much Corey! It's such a nice feeling to get all the code working and follow along. I really appreciate the list of contacts idea at the end, it seems so logical to do it that way and what can I say, I'm a big fan of logic! :) Thanks again! I'm loving your content and explanations.
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. al-taie.github.io/quick-mailer
I just bumped into your video. It is amazing. Thank you so much. I am so very new to Python and I think that this is one of the best tutorial I ahbe ever seen here on youtube. Thank you so much.
Very clear and simple.
this is really awesome and helpful. you simplify it so much. thank you!!
It works! Thank you.
Thanks for explaining each type in detail
I loved this one, it seems so simple to send emails here.
I can watch your videos on a tablet without getting blind... I'm going to thumbs up all your videos!
Super useful! Thank you.
This tutorial was so simple and straightforward. Super helpful. AND it worked!! Thanks, will be sure to check out your other videos.
@nikolaosboutsioukis3945
Жыл бұрын
Bro this feature was turned off by google couple of months ago how you say that it worked?
Thanks a lot helped me generate automatic email notifications in my web scraping project !! PS- Puppy is so cute :D
I implemented it my flask back-end for sending automated mails to those who subscribe 😎. Thanks a lot Corey for this fantastic video.
@venkataramanansundaresan321
3 жыл бұрын
can you send the code for it i am also trying to do the same but dont know how to do
@aakashjana6225
3 жыл бұрын
@@venkataramanansundaresan321 yes but where? Where exactly are stuck? You gotta create a mailing function where you pass in the mail address and it sends a mail everytime someone hits subscribe button on the website with their mail ID filled in from the input box
@Corey Schafer Thanx for posting such a comprehensive vid. None of the other videos on email via Python touched on Google settings regarding 2-step or TLS.
Thanks buddy you saved my project, I really appreciate your work.
Thank you, this clarified some questions.
Thanks, Corey. That worked great. Note that now you need to set up a App Password if you're using a Google account. This is to get around the 2-step verification process.
Hey Corey, you are real tech nerd. Video is awesome.
Only youtuber I can trust with python content!
Thanks a lot mate, I appreciate the effort you have put into making this video so easy to understand while also meeting the target of the intended title of the video. After looking online for a long time I finally came across your tutorial and I'm leaving with more information than I needed which is all so useful. So once again thanks a lot cus you made my day and all the best for the growth of your channel :))))
@alexvallex5487
2 жыл бұрын
do you know where in the code should i put by enviroment variable of the app password i
Thank u so much, Corey! Greetings from Mexico!
This was such an amazing video, it took me a lot of time to pause and then understand and then apply it to the code, but it just made me learn so much , you are such an amazing teacher sir, thanks for sharing your knowledge with us.🙏🙏🙏
Thank you man, worked first go!
This was really helpful. Thank you very much!
Amazing channel, subscribing right away
you explained things very nicely!
Very well. Thanks for Sharing.
Thanks for your work!
Thumbs up. Love all your vids, they are always so informative and useful.
works like a charm, thank you
Thank you Corey for another great video. Hope to see you back again in the future.
All your videos are "GOLD MINE" on the internet. I've learnt better with your videos than most others i've tried, I feel i owe you a lot , I'm making patreon contribution now!! Thanks a lott !!! god bless you Corey!!
@asega27
3 жыл бұрын
If this worked for you can you help me I hate to bother you
Thanks! This video made de subject more clear to me and I could follow the ressults
Very intuitive !
Loving your work! Thank you!
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options check out here: al-taie.github.io/quick-mailer
This is so helpful you have noooooooooo idea. Thank you cory!
Thanks for this great tutorial!!
You're just amazing guy ! thank you so much!
Thanks a lot, especially for the HTML part, it was the only thing it worked for me after trying a lot of different options
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. check out here: al-taie.github.io/quick-mailer
Oh man this video probably saved me hours of unnecessary struggle. If you could somehow get a link to this video as one of the top answers to google queries like "Python send email with attachment pdf" I bet you would get some extra traffic! Thank you so much for your work! I know that my learning process will be much smoother when I find one of your videos on the topic I want to learn. Youda best
Thank you sir, it helped me understand sending email in a simple way
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. al-taie.github.io/quick-mailer
Thanks a lot, It is just splendid explanation.
Thanks for the video. Its was very helpful
Thanks for the amazing video ☺️
Got a new subscriber because of the content of this video!
your channel is a gem mine :)
thanks a lot man it really helped
Thank u for this awesome video
like many of your videos, you got the best content and also every methods works :) thanks a lot mate!
This is sooo amazing and helpful thank you so much ❤️✨
great and easy to follow up
The Tutorial was very useful , it taught lot of stuff ,great work👍🏻 If anyone is getting Error for Environment Variable then just try by installing:- pip3 install python-dotenv then create '.env' file as it is mention your variable in that eg:- EMAIL_USER=abc@gmail.com EMAIL_PASS=abc@123 and python path lib USER=os.getenv('EMAIL_USER') PASS=os.getenv('EMAIL_PASS') just like that it's Done check by using print(USER,"",PASS).🤘🏻
thank you for this amazing video
Excellent! Thanks
Corey, i have some problems running the code if I write it as shown, but when copied to my VS it does ran great. Thank you for this great tutorial.
Thank you so much Corey
Love it! Thank you for being so amazing!
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. check out here: al-taie.github.io/quick-mailer
@fundtrading
Жыл бұрын
Hello what are you blasting with 🤞
this was so amazing!!! loved all your videos. big fan
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options check out here: al-taie.github.io/quick-mailer
Love you, man!
great tutorial thanks
Thank you for your video and pic sharing
Thanks a lot it works
Hello Corey, Thank you very much for this video. It's extremely clear, fast pace, super useful. BR, Anil
Thank you very much Corey. What could be the reason for someone to dislike such a valuable video?😂
thanks. the video is pretty extensive.
Thank You verry much body Respect for You
Thank you so much! 🙏
Thank you so much this video is realy helpfull
Awesome tutorial!!! This video just gave a idea for a new project Building a Custom Mailing Enterprise Software now. Thanks a lot!!
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. al-taie.github.io/quick-mailer
@debjitchattopadhyay7627
3 жыл бұрын
@@al-taie thanks 👍
Excellent video Corey! The steps were very clearly explained and worked without any issues. One question - the example that you provide is for including multiple attachments to a single email; however, if I wish to include the list of attachments to individual emails (one attachment per email), what would be the best way to proceed? I have looked this up in details and not found a satisfactory solution. Will greatly appreciate your help with this.
Great tutorial
Great video, Corey! I am a total newbie to Python, and you made this so easy to follow. Could you possibly create a video or point me towards a resource where a Python script is used to send an HTML email with variable data from a SQL query? For example, if I wanted to email a simple summary report with the sum of deposit balances, deposit counts, loan balances, and loan counts with HTML formatting, could this be done with a Python script?
this video is amazing
Thanks so much
Thank you Corey for the video. It will be really nice if you can make a video about how to read emails from Gmail
Another wonderful video!
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. check out here: al-taie.github.io/quick-mailer
you are genius..........thank a lot of about what you doing with your lightfully teaching..... you are one of the best teacher in this world...god bless you and your family too....................you are a light for our brains
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options. check out here: al-taie.github.io/quick-mailer
Thanks for the video
Great, Thanks
thank you!
woow great god bless ya sir
thank you so much
YOU ARE THE GOAT COREY
you saved alot of nerves
Thanks Corey!!
*Question on HTML email:* *[SOVED]* Is there a way to send a HTML email without having to write it manually in triple quote, but more automated? Like if I had a file called "email.html", and I didn't want to send it as an attachment, but the email itself. Thanks, anyone. EDIT: I found a solution! If anyone is interested here it is; ### with open('my_HTML_file.html', 'rb') as f: file_data = f.read() file_type = imghdr.what(f.name) file_name = f.name #print(file_data) file_string = file_data.decode(encoding='UTF-8') #print(" ::: The file decoded into a string ::: ", file_string) msg.add_alternative(file_string, subtype='html') ###
@diplomat1837
4 жыл бұрын
Where does this code comes in the code. I’ve been having alternative error when I tried sending the HTML link on the code. Please some help to get me through
@ajith_e
3 жыл бұрын
Hey, Thanks man !! I was just searching for the same. I have an external html file read into the script. That was semantic
Thanks
You make me so happy! Can’t wait to watch this video lol
Excellent!
thanks for this, very helpful.
@al-taie
3 жыл бұрын
You can use (quick-mailer) module, to send email in two lines of code, with a lot of options check out here: al-taie.github.io/quick-mailer
keep doing good stuff !