title
How to Send Emails Using Python - Plain Text, Adding Attachments, HTML Emails, and More

description
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: http://bit.ly/python-emails Google Account Settings: https://myaccount.google.com/lesssecureapps https://myaccount.google.com/apppasswords Environment Variables (Windows) - https://youtu.be/IolxqkL7cD8 Environment Variables (Mac and Linux) - https://youtu.be/5iWhQWVXosU Lists Tutorial - https://youtu.be/W8KRzm-HUcc ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python

detail
{'title': 'How to Send Emails Using Python - Plain Text, Adding Attachments, HTML Emails, and More', 'heatmap': [{'end': 116.854, 'start': 76.172, 'weight': 0.763}, {'end': 577.624, 'start': 534.808, 'weight': 0.961}], 'summary': 'Learn to send emails using python with a focus on gmail configuration, secure scripting, testing, message optimization, attaching images and files, and tips for sending html emails and attachments, including best practices for securing sensitive information.', 'chapters': [{'end': 136.298, 'segs': [{'end': 29.008, 'src': 'embed', 'start': 0.229, 'weight': 0, 'content': [{'end': 4.213, 'text': "Hey there, how's it going everybody? In this video, we're going to be learning how to send emails with Python.", 'start': 0.229, 'duration': 3.984}, {'end': 6.455, 'text': "So we've sent emails in previous videos.", 'start': 4.553, 'duration': 1.902}, {'end': 10.439, 'text': "But in this video, we're going to look at this more in depth and see how to use best practices.", 'start': 6.735, 'duration': 3.704}, {'end': 16.224, 'text': "And we're also going to look at how to do more advanced emails such as adding attachments or sending HTML messages.", 'start': 10.719, 'duration': 5.505}, {'end': 17.786, 'text': "So let's go ahead and get started.", 'start': 16.585, 'duration': 1.201}, {'end': 21.667, 'text': "So first of all, you're going to want to have an email account to send emails.", 'start': 18.286, 'duration': 3.381}, {'end': 26.168, 'text': "In this video, we're going to be using Gmail, which most of you are likely familiar with.", 'start': 22.007, 'duration': 4.161}, {'end': 29.008, 'text': "But you can use any email service that you'd like.", 'start': 26.808, 'duration': 2.2}], 'summary': 'Learn to send emails with python, including advanced features like attachments and html messages. gmail will be used as an example.', 'duration': 28.779, 'max_score': 0.229, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU229.jpg'}, {'end': 75.832, 'src': 'embed', 'start': 34.009, 'weight': 1, 'content': [{'end': 41.051, 'text': "Now we're also going to see how we can use your localhost to send test emails if you don't have an actual email address set up yet.", 'start': 34.009, 'duration': 7.042}, {'end': 45.732, 'text': "But for now, let's look at some stuff that we need to do to get an account ready.", 'start': 41.731, 'duration': 4.001}, {'end': 48.673, 'text': "So, for example, if you're using Gmail,", 'start': 46.312, 'duration': 2.361}, {'end': 54.215, 'text': 'then there are a couple of settings that you need to change in order to send emails through Python using this account.', 'start': 48.673, 'duration': 5.542}, {'end': 56.456, 'text': 'So let me pull these up in my browser.', 'start': 54.575, 'duration': 1.881}, {'end': 64.578, 'text': 'So one is this myaccount.google.com forward slash less secure apps.', 'start': 56.856, 'duration': 7.722}, {'end': 68.302, 'text': "So first, if you don't have two-factor authentication set up,", 'start': 65.018, 'duration': 3.284}, {'end': 72.948, 'text': "then you're going to need to allow less secure applications like Python to connect to your account.", 'start': 68.302, 'duration': 4.646}, {'end': 75.832, 'text': 'And you can do that at this URL here.', 'start': 73.389, 'duration': 2.443}], 'summary': 'Guide on setting up gmail for sending emails through python', 'duration': 41.823, 'max_score': 34.009, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU34009.jpg'}, {'end': 136.298, 'src': 'heatmap', 'start': 76.172, 'weight': 2, 'content': [{'end': 82.2, 'text': "And I'll have links to these pages in the description section below if you want to access these URLs.", 'start': 76.172, 'duration': 6.028}, {'end': 86.202, 'text': 'now, if you do have two-factor authentication, which I would always recommend,', 'start': 82.6, 'duration': 3.602}, {'end': 91.964, 'text': "then instead you'll need to create an app password so that you can connect through Python,", 'start': 86.202, 'duration': 5.762}, {'end': 97.107, 'text': 'and you will do that at this URL here myaccount.google.com.', 'start': 91.964, 'duration': 5.143}, {'end': 105.951, 'text': 'forward slash app passwords so you can see that I have an app password here called Python test, and this is what I use to connect to my account.', 'start': 97.107, 'duration': 8.844}, {'end': 112.533, 'text': "now I've placed that password into an environment variable so that I never need to add it directly into a Python script.", 'start': 105.951, 'duration': 6.582}, {'end': 116.854, 'text': "I think it's a good habit to never add your sensitive information directly to your script,", 'start': 112.853, 'duration': 4.001}, {'end': 123.135, 'text': "but instead you should use configuration files that don't get committed to source control or use environment variables.", 'start': 116.854, 'duration': 6.281}, {'end': 126.776, 'text': "So if you've never used environment variables to hide information like this,", 'start': 123.516, 'duration': 3.26}, {'end': 131.037, 'text': 'then I do have a separate video that shows how to do that for Mac Linux and Windows.', 'start': 126.776, 'duration': 4.261}, {'end': 136.298, 'text': "So I'll leave a link to those videos in the description section below if anyone would like to see how that's done.", 'start': 131.357, 'duration': 4.941}], 'summary': 'Use app password and environment variables to connect to google account securely.', 'duration': 39.191, 'max_score': 76.172, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU76172.jpg'}], 'start': 0.229, 'title': 'Sending emails with python', 'summary': 'Covers sending emails using python, focusing on gmail configuration, allowing less secure apps, creating app passwords for two-factor authentication, and best practices for handling sensitive information.', 'chapters': [{'end': 136.298, 'start': 0.229, 'title': 'Sending emails with python', 'summary': 'Covers the process of sending emails using python, focusing on using gmail and configuring settings, including allowing less secure apps and creating app passwords for two-factor authentication, and best practices for handling sensitive information.', 'duration': 136.069, 'highlights': ['The chapter covers the process of sending emails using Python, focusing on using Gmail and configuring settings, including allowing less secure apps and creating app passwords for two-factor authentication, and best practices for handling sensitive information.', 'The tutorial emphasizes the importance of best practices for handling sensitive information, such as using configuration files or environment variables to store sensitive data instead of directly adding it to the Python script.', 'Instructions are provided for configuring Gmail settings to allow less secure apps or creating app passwords for two-factor authentication, with links to the relevant URLs for reference.', 'The video also demonstrates how to use localhost to send test emails if an actual email address is not set up yet, providing practical solutions for testing email functionality.', 'The chapter highlights the significance of using environment variables to hide sensitive information and provides references to separate tutorials for setting up environment variables on Mac, Linux, and Windows.']}], 'duration': 136.069, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU229.jpg', 'highlights': ['The chapter covers the process of sending emails using Python, focusing on using Gmail and configuring settings, including allowing less secure apps and creating app passwords for two-factor authentication.', 'Instructions are provided for configuring Gmail settings to allow less secure apps or creating app passwords for two-factor authentication, with links to the relevant URLs for reference.', 'The tutorial emphasizes the importance of best practices for handling sensitive information, such as using configuration files or environment variables to store sensitive data instead of directly adding it to the Python script.', 'The video also demonstrates how to use localhost to send test emails if an actual email address is not set up yet, providing practical solutions for testing email functionality.', 'The chapter highlights the significance of using environment variables to hide sensitive information and provides references to separate tutorials for setting up environment variables on Mac, Linux, and Windows.']}, {'end': 392.183, 'segs': [{'end': 206.027, 'src': 'embed', 'start': 158.683, 'weight': 1, 'content': [{'end': 162.684, 'text': 'because that will conflict with the module built in to the standard library.', 'start': 158.683, 'duration': 4.001}, {'end': 164.845, 'text': 'So I have mine called mail-demo.py.', 'start': 163.024, 'duration': 1.821}, {'end': 168.967, 'text': "Okay, so first let's connect to the mail server.", 'start': 166.565, 'duration': 2.402}, {'end': 172.089, 'text': 'Now there are two different classes that we can use to do this.', 'start': 169.327, 'duration': 2.762}, {'end': 176.472, 'text': 'And both of those are going to be imported from the SMTP lib module.', 'start': 172.449, 'duration': 4.023}, {'end': 178.694, 'text': "So I'll just import that entire module.", 'start': 176.852, 'duration': 1.842}, {'end': 181.696, 'text': "So I'll say import SMTP lib.", 'start': 178.954, 'duration': 2.742}, {'end': 185.538, 'text': "So first, I'm going to go ahead and connect using plain old SMTP.", 'start': 182.276, 'duration': 3.262}, {'end': 187.759, 'text': "So I'm going to use a context manager here.", 'start': 185.918, 'duration': 1.841}, {'end': 194.282, 'text': 'And using a context manager will make sure that our connection is closed automatically without us needing to do it manually.', 'start': 188.179, 'duration': 6.103}, {'end': 200.145, 'text': "So I'm just going to say with SMTP lib dot SMTP.", 'start': 194.622, 'duration': 5.523}, {'end': 202.746, 'text': "So we're using the SMTP class there.", 'start': 200.545, 'duration': 2.201}, {'end': 206.027, 'text': "And now we'll put in the mail server that we want to use.", 'start': 203.366, 'duration': 2.661}], 'summary': 'Connecting to mail server using smtp lib, with automatic connection closure.', 'duration': 47.344, 'max_score': 158.683, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU158683.jpg'}, {'end': 315.993, 'src': 'embed', 'start': 284.271, 'weight': 0, 'content': [{'end': 288.355, 'text': 'And now we can put in our email address and password that we want to log in with.', 'start': 284.271, 'duration': 4.084}, {'end': 291.997, 'text': 'Now you can put this directly into the script, but remember,', 'start': 288.795, 'duration': 3.202}, {'end': 297.361, 'text': "I said that I think it's a good idea to get into the habit of putting sensitive information into environment variables.", 'start': 291.997, 'duration': 5.364}, {'end': 299.642, 'text': "So that's where I currently have mine.", 'start': 297.741, 'duration': 1.901}, {'end': 303.825, 'text': "So at the top of my script, I'm going to go ahead and grab these environment variables.", 'start': 300.083, 'duration': 3.742}, {'end': 306.747, 'text': 'So I can do that with the OS module.', 'start': 304.165, 'duration': 2.582}, {'end': 309.989, 'text': "So above SMTP here, I'm going to import OS.", 'start': 307.067, 'duration': 2.922}, {'end': 315.993, 'text': "And now here at the top of the file, I'm going to create some variables using these environment variables.", 'start': 310.51, 'duration': 5.483}], 'summary': 'Recommend using environment variables for sensitive information like email and password.', 'duration': 31.722, 'max_score': 284.271, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU284271.jpg'}], 'start': 136.738, 'title': 'Sending emails and secure scripting in python', 'summary': "Covers sending emails using python's smtp lib module, emphasizing server configuration, port number, encryption, and login process. it also discusses using environment variables to securely store sensitive information for secure scripting, highlighting the use of os module and best practices for securing sensitive data.", 'chapters': [{'end': 206.027, 'start': 136.738, 'title': 'Sending emails with python', 'summary': 'Discusses connecting to a mail server and sending emails using python, emphasizing the use of smtp lib module and the importance of naming scripts to avoid conflicts with the standard library module.', 'duration': 69.289, 'highlights': ["The chapter emphasizes the importance of not naming the script as 'email.py' to avoid conflicts with the standard library module.", 'It discusses the use of a context manager to automatically close the connection to the mail server, ensuring convenient management of connections.', 'The chapter introduces the use of the SMTP lib module for connecting to the mail server and sending emails using Python.']}, {'end': 283.771, 'start': 206.387, 'title': 'Configuring smtp in python', 'summary': 'Explains how to configure smtp settings in python, including setting up the server, port number, encryption, and logging in to the mail server.', 'duration': 77.384, 'highlights': ['The chapter explains how to configure SMTP settings in Python, including setting up the server, port number, encryption, and logging in to the mail server.', 'smtp.startTLS is used to encrypt the traffic, and the EHLO method is rerun to re-identify the connection as encrypted.', 'The transcript provides the server address, port number, and the process of logging in to the mail server.']}, {'end': 392.183, 'start': 284.271, 'title': 'Using environment variables for secure scripting', 'summary': 'Demonstrates the use of environment variables to securely store and access sensitive information, such as email address and password, for logging into a mail server in python, providing insights on the use of os module and the importance of securing sensitive information with environment variables.', 'duration': 107.912, 'highlights': ['Demonstrates the use of environment variables to securely store sensitive information The chapter emphasizes the importance of using environment variables to store sensitive information such as email address and password, promoting secure scripting practices.', 'Accessing environment variables using OS module in Python The use of OS module to access environment variables in Python is illustrated, showcasing the process of retrieving sensitive information securely from environment variables.', 'Logging into a mail server using credentials stored in environment variables The chapter provides a practical example of utilizing credentials stored in environment variables to log into a mail server, emphasizing the secure handling of sensitive information.']}], 'duration': 255.445, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU136738.jpg', 'highlights': ['The chapter emphasizes the importance of using environment variables to securely store sensitive information such as email address and password, promoting secure scripting practices.', 'The chapter explains how to configure SMTP settings in Python, including setting up the server, port number, encryption, and logging in to the mail server.', 'The chapter introduces the use of the SMTP lib module for connecting to the mail server and sending emails using Python.', 'The chapter provides a practical example of utilizing credentials stored in environment variables to log into a mail server, emphasizing the secure handling of sensitive information.', 'The chapter introduces the use of a context manager to automatically close the connection to the mail server, ensuring convenient management of connections.']}, {'end': 802.717, 'segs': [{'end': 452.238, 'src': 'embed', 'start': 423.777, 'weight': 5, 'content': [{'end': 430.381, 'text': 'you need to add the subject as a header and then have a couple of blank lines and then put the body of the message.', 'start': 423.777, 'duration': 6.604}, {'end': 432.802, 'text': "So I'm going to do this using an F string.", 'start': 430.721, 'duration': 2.081}, {'end': 437.445, 'text': "So I'm going to say MSG is equal to, and now I'm going to create an F string.", 'start': 433.203, 'duration': 4.242}, {'end': 438.406, 'text': "So we'll put an F there.", 'start': 437.485, 'duration': 0.921}, {'end': 441.708, 'text': 'And now we need to put the subject as a header.', 'start': 439.026, 'duration': 2.682}, {'end': 444.229, 'text': "So I'll say subject and then put in MSG.", 'start': 441.808, 'duration': 2.421}, {'end': 452.238, 'text': 'our subject there and now we need a couple of blank lines and now we can put in the body of our message.', 'start': 445.47, 'duration': 6.768}], 'summary': 'Using f string to add subject header and body to message.', 'duration': 28.461, 'max_score': 423.777, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU423777.jpg'}, {'end': 492.269, 'src': 'embed', 'start': 464.691, 'weight': 0, 'content': [{'end': 468.614, 'text': "if you've never used f-strings before, then you can use regular string formatting there as well.", 'start': 464.691, 'duration': 3.923}, {'end': 472.937, 'text': 'But basically, you just need your subject, those two new lines, and then your body.', 'start': 469.154, 'duration': 3.783}, {'end': 477.34, 'text': 'Okay, so now we can send this simple plain text email.', 'start': 473.457, 'duration': 3.883}, {'end': 482.623, 'text': 'So to do this, I can just say smtp.sendmail.', 'start': 477.8, 'duration': 4.823}, {'end': 488.868, 'text': 'And now the format that we are going to use for this is going to be the sender.', 'start': 483.324, 'duration': 5.544}, {'end': 492.269, 'text': 'then the receiver, and then the message.', 'start': 489.668, 'duration': 2.601}], 'summary': 'Introduction to using f-strings and sending simple plain text email via smtp', 'duration': 27.578, 'max_score': 464.691, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU464691.jpg'}, {'end': 577.624, 'src': 'heatmap', 'start': 534.808, 'weight': 1, 'content': [{'end': 539.111, 'text': "So if you don't mind, please change that to your own address for testing purposes.", 'start': 534.808, 'duration': 4.303}, {'end': 544.434, 'text': "Okay, so for sending simple plain text emails, then it's just as simple as this.", 'start': 540.071, 'duration': 4.363}, {'end': 550.657, 'text': "So if I save this, then we can see if I scroll up here, we've done this in 20 lines of code.", 'start': 544.834, 'duration': 5.823}, {'end': 553.198, 'text': 'So now I can go ahead and run this.', 'start': 551.077, 'duration': 2.121}, {'end': 555.599, 'text': "And we didn't have any output, so that's fine.", 'start': 553.698, 'duration': 1.901}, {'end': 556.6, 'text': "We didn't print anything.", 'start': 555.619, 'duration': 0.981}, {'end': 563.948, 'text': 'But if I go back to my browser here, then if I pull up my email here, then we can see that I got my message.', 'start': 557.34, 'duration': 6.608}, {'end': 565.009, 'text': "So that's good.", 'start': 564.108, 'duration': 0.901}, {'end': 574.74, 'text': "Now if you're doing a lot of testing and don't actually want to send yourself an email each time, then you can use a local debug server to test this.", 'start': 565.85, 'duration': 8.89}, {'end': 577.624, 'text': "So next we're going to take a look at how to do that.", 'start': 575.141, 'duration': 2.483}], 'summary': 'Sending simple plain text emails in 20 lines of code, successful testing with local debug server.', 'duration': 42.816, 'max_score': 534.808, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU534808.jpg'}, {'end': 802.717, 'src': 'embed', 'start': 775.378, 'weight': 2, 'content': [{'end': 782.983, 'text': 'Now, if we wanted to, then we could just use the SMTP SSL class to have an SSL connection from the very beginning,', 'start': 775.378, 'duration': 7.605}, {'end': 785.025, 'text': "and then we won't have to run these other commands.", 'start': 782.983, 'duration': 2.042}, {'end': 793.29, 'text': "So to do this, instead of using the SMTP class, I'm going to use SMTP underscore SSL.", 'start': 785.465, 'duration': 7.825}, {'end': 802.717, 'text': "And when you use an SSL connection, instead of this being on port 587, we're now going to use port 465.", 'start': 793.791, 'duration': 8.926}], 'summary': 'Using smtp ssl class for ssl connection, switching to port 465.', 'duration': 27.339, 'max_score': 775.378, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU775378.jpg'}], 'start': 392.183, 'title': 'Sending and testing emails with python', 'summary': 'Discusses creating a simple plain text email using python, constructing the subject and body of the message, formatting the email using f string, and sending the email via smtp.sendmail. it also demonstrates sending simple plain text emails, using a local debug server to test emails, and using smtp ssl for an ssl connection.', 'chapters': [{'end': 488.868, 'start': 392.183, 'title': 'Creating plain text email', 'summary': 'Discusses creating a simple plain text email using python, including constructing the subject and body of the message, formatting the email using f string, and sending the email via smtp.sendmail.', 'duration': 96.685, 'highlights': ['Constructing a plain text email from scratch involves adding the subject as a header and then having a couple of blank lines before putting the body of the message, demonstrated by creating an F string to format the email message.', 'The process of creating a simple plain text email using Python is explained, including setting the subject as a header and adding the body of the message, providing insights into the formatting methods.', 'The method of sending a simple plain text email using Python is elucidated as smtp.sendmail, offering a straightforward approach to email communication.']}, {'end': 802.717, 'start': 489.668, 'title': 'Sending and testing emails with python', 'summary': 'Demonstrates how to send and test emails using python, including sending simple plain text emails, using a local debug server to test emails, and using smtp ssl for an ssl connection.', 'duration': 313.049, 'highlights': ['The chapter demonstrates sending simple plain text emails in 20 lines of code and successfully running them. The demonstration includes sending simple plain text emails in 20 lines of code and successfully running them.', 'The chapter explains using a local debug server to test emails, which involves starting a debug mail server on the local host and sending an email to the debug server for testing. The chapter explains using a local debug server to test emails, involving starting a debug mail server on the local host and sending an email to the debug server for testing.', 'The chapter discusses using SMTP SSL for an SSL connection by using the SMTP_SSL class and changing the port to 465, eliminating the need to run other commands like EHLO and start TLS. The chapter discusses using SMTP SSL for an SSL connection by using the SMTP_SSL class and changing the port to 465, eliminating the need to run other commands like EHLO and start TLS.']}], 'duration': 410.534, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU392183.jpg', 'highlights': ['The method of sending a simple plain text email using Python is elucidated as smtp.sendmail, offering a straightforward approach to email communication.', 'The chapter demonstrates sending simple plain text emails in 20 lines of code and successfully running them.', 'The chapter discusses using SMTP SSL for an SSL connection by using the SMTP_SSL class and changing the port to 465, eliminating the need to run other commands like EHLO and start TLS.', 'The process of creating a simple plain text email using Python is explained, including setting the subject as a header and adding the body of the message, providing insights into the formatting methods.', 'The chapter explains using a local debug server to test emails, involving starting a debug mail server on the local host and sending an email to the debug server for testing.', 'Constructing a plain text email from scratch involves adding the subject as a header and then having a couple of blank lines before putting the body of the message, demonstrated by creating an F string to format the email message.']}, {'end': 1035.265, 'segs': [{'end': 841.47, 'src': 'embed', 'start': 802.717, 'weight': 3, 'content': [{'end': 805.418, 'text': 'And now we can remove these other lines here.', 'start': 802.717, 'duration': 2.701}, {'end': 808.681, 'text': "So I'm just going to remove these other lines here.", 'start': 805.719, 'duration': 2.962}, {'end': 811.763, 'text': "And now we're just simply logging in and sending our message.", 'start': 809.061, 'duration': 2.702}, {'end': 817.868, 'text': 'So if I save this and go back to my browser here, Then we can see that that still works too.', 'start': 812.083, 'duration': 5.785}, {'end': 819.369, 'text': 'I still got that new email.', 'start': 817.948, 'duration': 1.421}, {'end': 828.037, 'text': "Okay, so the other thing that's a bit weird back in our code, let me delete that test email so that we're sure that we're working with a clean slate.", 'start': 819.91, 'duration': 8.127}, {'end': 829.359, 'text': 'Let me go back to the code.', 'start': 828.057, 'duration': 1.302}, {'end': 835.665, 'text': "Okay, so another thing that is a bit weird is the formatting that we're using with our message.", 'start': 829.839, 'duration': 5.826}, {'end': 841.47, 'text': "it's not really intuitive that we have our subject and then the two blank lines and then our body.", 'start': 836.025, 'duration': 5.445}], 'summary': 'Removing unnecessary lines, logging in, and sending a message; ensuring clean slate for testing; addressing formatting issues.', 'duration': 38.753, 'max_score': 802.717, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU802717.jpg'}, {'end': 881.284, 'src': 'embed', 'start': 861.068, 'weight': 0, 'content': [{'end': 873.198, 'text': "so this is an email message class and now we can use this email message to set these things a bit more cleanly and we don't even need to create this message inside of our with statement.", 'start': 861.068, 'duration': 12.13}, {'end': 881.284, 'text': "so let's instead build this up at the top of our file here and then just use our with statement to log in and send the message.", 'start': 873.198, 'duration': 8.086}], 'summary': 'Email message class simplifies creation and usage, improving code readability and efficiency.', 'duration': 20.216, 'max_score': 861.068, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU861068.jpg'}, {'end': 1014.533, 'src': 'embed', 'start': 992.264, 'weight': 1, 'content': [{'end': 1000.487, 'text': "So I'm going to get rid of those and just have the message there and this is going to be send underscore message.", 'start': 992.264, 'duration': 8.223}, {'end': 1005.149, 'text': 'Okay so I think that this organizes the information for our message a little bit better.', 'start': 1000.928, 'duration': 4.221}, {'end': 1013.573, 'text': 'So now we have it all in one place, and not only that, but this is also going to let us put together some more complicated messages as well,', 'start': 1005.529, 'duration': 8.044}, {'end': 1014.533, 'text': 'with us doing it this way.', 'start': 1013.573, 'duration': 0.96}], 'summary': 'Organized message information, enabling creation of complex messages.', 'duration': 22.269, 'max_score': 992.264, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU992264.jpg'}], 'start': 802.717, 'title': 'Email message optimization', 'summary': 'Covers email formatting, testing, and improved message handling, emphasizing the removal of unnecessary lines, addressing formatting issues, and utilizing the email message class to enhance message creation and organization.', 'chapters': [{'end': 841.47, 'start': 802.717, 'title': 'Email formatting and testing', 'summary': 'Discusses email formatting and testing, highlighting the removal of unnecessary lines, logging in and sending messages, and the need to address formatting issues for better user experience.', 'duration': 38.753, 'highlights': ['The need to address formatting issues for better user experience', 'The removal of unnecessary lines', 'Logging in and sending messages']}, {'end': 1035.265, 'start': 841.47, 'title': 'Improved email message handling', 'summary': 'Demonstrates how to enhance email message handling by utilizing the email message class to set up and send messages more efficiently, enabling the creation of more complex messages, resulting in improved organization and functionality.', 'duration': 193.795, 'highlights': ['Utilizing the email message class to set up and send messages more efficiently By using the email message class, the message parts can be set more cleanly and the message can be built at the top of the file, simplifying the process and making it more organized.', 'Enabling the creation of more complex messages The new approach allows for the creation of more complicated messages, providing greater flexibility and functionality in the email content.', 'Demonstrating improved organization and functionality The new method organizes the information for the message in one place, resulting in better organization and allowing for the creation of more complex messages, while still ensuring the proper functioning of the email system.']}], 'duration': 232.548, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU802717.jpg', 'highlights': ['Utilizing the email message class to set up and send messages more efficiently', 'Demonstrating improved organization and functionality', 'Enabling the creation of more complex messages', 'The need to address formatting issues for better user experience', 'The removal of unnecessary lines', 'Logging in and sending messages']}, {'end': 1504.487, 'segs': [{'end': 1134.831, 'src': 'embed', 'start': 1035.606, 'weight': 0, 'content': [{'end': 1040.609, 'text': "Okay, so now we're using this new email message object to send our message.", 'start': 1035.606, 'duration': 5.003}, {'end': 1043.833, 'text': "So now let's see how we can add some attachments to this email.", 'start': 1040.91, 'duration': 2.923}, {'end': 1049.498, 'text': 'So I have some pictures of my dog when he was a puppy saved in the same directory as this script.', 'start': 1044.213, 'duration': 5.285}, {'end': 1053.321, 'text': "So let's say that I wanted to add those as an email attachment.", 'start': 1049.838, 'duration': 3.483}, {'end': 1059.586, 'text': "So first I'll just attach one image and then we'll see how to do two after we send the one.", 'start': 1053.821, 'duration': 5.765}, {'end': 1065.41, 'text': "So first I'm going to change the subject and the body of our message here.", 'start': 1060.046, 'duration': 5.364}, {'end': 1069.753, 'text': "So I'll just say check out Bronx as a puppy.", 'start': 1065.77, 'duration': 3.983}, {'end': 1074.515, 'text': "And then for the content here, I will just let them know that there's an image attached.", 'start': 1070.994, 'duration': 3.521}, {'end': 1077.116, 'text': "So I'll just say imaged attached here.", 'start': 1074.855, 'duration': 2.261}, {'end': 1084.117, 'text': "Okay, so now below set content here, I'm going to open that file that I want to attach.", 'start': 1077.136, 'duration': 6.981}, {'end': 1087.618, 'text': 'So to open this file, I can just say with open.', 'start': 1084.537, 'duration': 3.081}, {'end': 1092.099, 'text': "And this file is in the same directory as my current script that I'm running.", 'start': 1088.278, 'duration': 3.821}, {'end': 1094.06, 'text': "So I don't have to set a full path or anything.", 'start': 1092.159, 'duration': 1.901}, {'end': 1097.883, 'text': 'But you would set the full path to the image that you want to attach.', 'start': 1094.46, 'duration': 3.423}, {'end': 1101.906, 'text': 'And this image for me is called Bronx1.jpg.', 'start': 1098.423, 'duration': 3.483}, {'end': 1106.59, 'text': "So I'm going to open that as an RB mode, which is read bytes.", 'start': 1102.427, 'duration': 4.163}, {'end': 1109.252, 'text': 'And I will just call this F.', 'start': 1107.09, 'duration': 2.162}, {'end': 1113.015, 'text': 'So now within here, I can read that image data.', 'start': 1109.252, 'duration': 3.763}, {'end': 1114.937, 'text': "So I'll say file data is equal to F.", 'start': 1113.195, 'duration': 1.742}, {'end': 1119.84, 'text': 'dot read and now we can attach this to our message.', 'start': 1116.698, 'duration': 3.142}, {'end': 1125.444, 'text': "but before we attach this, we're going to need to be able to determine what kind of image we're attaching.", 'start': 1119.84, 'duration': 5.604}, {'end': 1129.507, 'text': "so if we're just doing one image, then we could put this in manually.", 'start': 1125.444, 'duration': 4.063}, {'end': 1134.831, 'text': "but if you're doing multiple images, then you're likely going to want Python to determine this for us.", 'start': 1129.507, 'duration': 5.324}], 'summary': 'Demonstrating how to add attachments to an email message, starting with one image and discussing the process for adding multiple images.', 'duration': 99.225, 'max_score': 1035.606, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1035606.jpg'}, {'end': 1182, 'src': 'embed', 'start': 1157.546, 'weight': 3, 'content': [{'end': 1165.332, 'text': 'And now to get the type of image that this is within our with statement down here, where we have this image file open,', 'start': 1157.546, 'duration': 7.786}, {'end': 1172.416, 'text': "I'm going to say file underscore type is equal to imghdr dot.", 'start': 1165.332, 'duration': 7.084}, {'end': 1173.217, 'text': 'what this is?', 'start': 1172.416, 'duration': 0.801}, {'end': 1174.877, 'text': 'a dot, what method?', 'start': 1173.217, 'duration': 1.66}, {'end': 1178.079, 'text': 'and now we can just pass in that name of that file.', 'start': 1174.877, 'duration': 3.202}, {'end': 1179.859, 'text': "so I'm going to say f dot name.", 'start': 1178.079, 'duration': 1.78}, {'end': 1182, 'text': "so we're passing in the name of the file.", 'start': 1179.859, 'duration': 2.141}], 'summary': "Identifying the type of image file using 'imghdr' method and passing the file name.", 'duration': 24.454, 'max_score': 1157.546, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1157546.jpg'}, {'end': 1439.979, 'src': 'embed', 'start': 1408.963, 'weight': 2, 'content': [{'end': 1413.327, 'text': "so when it loops through this, we're going to open bronx1.jpg.", 'start': 1408.963, 'duration': 4.364}, {'end': 1417.39, 'text': 'read in that data, get the file type, get the file name and attach that to our message.', 'start': 1413.327, 'duration': 4.063}, {'end': 1425.773, 'text': "And then it's going to move on to bronx2.jpg, get the file data, file type, file name, and then add that as an attachment to our message.", 'start': 1417.73, 'duration': 8.043}, {'end': 1431.496, 'text': 'So if I save that and run it, then this one will probably take even longer to.', 'start': 1426.153, 'duration': 5.343}, {'end': 1439.979, 'text': 'come in now, but if I check the browser, then let me go back to my inbox and it looks like this came in here.', 'start': 1432.436, 'duration': 7.543}], 'summary': 'Looped through 2 jpeg files to attach to message.', 'duration': 31.016, 'max_score': 1408.963, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1408963.jpg'}, {'end': 1485.75, 'src': 'embed', 'start': 1456.987, 'weight': 1, 'content': [{'end': 1459.929, 'text': 'Okay, so attaching both of those images to our email worked well.', 'start': 1456.987, 'duration': 2.942}, {'end': 1466.694, 'text': "Now if you're attaching some other kind of file, then you just need to change the main type and the subtype for each one.", 'start': 1460.61, 'duration': 6.084}, {'end': 1472.919, 'text': 'So I also have a PDF in the same directory as my script here.', 'start': 1467.254, 'duration': 5.665}, {'end': 1478.504, 'text': 'So if I wanted to send something like a PDF, then I could go ahead and do something like this.', 'start': 1473.26, 'duration': 5.244}, {'end': 1480.726, 'text': "So I'm just going to keep my for loop here.", 'start': 1478.824, 'duration': 1.902}, {'end': 1485.75, 'text': "But for the files up here, I'm just going to make this a list of one file.", 'start': 1481.407, 'duration': 4.343}], 'summary': 'Attaching both images to email; discussing file types and pdf attachment.', 'duration': 28.763, 'max_score': 1456.987, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1456987.jpg'}], 'start': 1035.606, 'title': 'Python email attachment', 'summary': 'Details the process of attaching images to an email using a new email message object, including the steps to change the subject and body of the message, open the file, read the image data, and determine the type of image being attached. it also demonstrates how to attach images and other files to an email using python, including extracting image type and attaching multiple images.', 'chapters': [{'end': 1134.831, 'start': 1035.606, 'title': 'Attaching images to email', 'summary': 'Details the process of attaching images to an email using a new email message object, including the steps to change the subject and body of the message, open the file, read the image data, and determine the type of image being attached.', 'duration': 99.225, 'highlights': ['The process of attaching images to an email using a new email message object is explained. Using a new email message object to send the message, changing the subject and body of the message, opening the file, and reading the image data.', "The steps to change the subject and body of the message are outlined. Changing the subject to 'check out Bronx as a puppy' and informing about the attached image in the body of the message.", "Instructions for opening the file and reading the image data are provided. Opening the file 'Bronx1.jpg' and reading the image data using the 'read bytes' mode.", 'The importance of determining the type of image being attached is highlighted. The need to determine the type of image being attached, especially when dealing with multiple images.']}, {'end': 1504.487, 'start': 1134.831, 'title': 'Python email attachment', 'summary': 'Demonstrates how to attach images and other files to an email using python, including extracting image type and attaching multiple images.', 'duration': 369.656, 'highlights': ['The module imghdr is used to obtain the type of image by passing in the name of the file, returning the image type, such as JPEG.', 'Demonstrates attaching an image to an email using Python, specifying the file data, main type as an image, subtype as the image type, and the file name for the attachment.', 'Illustrates the process of attaching multiple images to an email by creating a loop to iterate through a list of file names, opening each file, reading its data, obtaining the file type, and attaching it to the message.']}], 'duration': 468.881, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1035606.jpg', 'highlights': ['The process of attaching images to an email using a new email message object is explained. Using a new email message object to send the message, changing the subject and body of the message, opening the file, and reading the image data.', 'Demonstrates attaching an image to an email using Python, specifying the file data, main type as an image, subtype as the image type, and the file name for the attachment.', 'Illustrates the process of attaching multiple images to an email by creating a loop to iterate through a list of file names, opening each file, reading its data, obtaining the file type, and attaching it to the message.', 'The module imghdr is used to obtain the type of image by passing in the name of the file, returning the image type, such as JPEG.', "The steps to change the subject and body of the message are outlined. Changing the subject to 'check out Bronx as a puppy' and informing about the attached image in the body of the message.", "Instructions for opening the file and reading the image data are provided. Opening the file 'Bronx1.jpg' and reading the image data using the 'read bytes' mode.", 'The importance of determining the type of image being attached is highlighted. The need to determine the type of image being attached, especially when dealing with multiple images.']}, {'end': 1903.852, 'segs': [{'end': 1530.857, 'src': 'embed', 'start': 1504.987, 'weight': 2, 'content': [{'end': 1512.91, 'text': "And now for the when we add the attachment, what we're going to do here as the main type is we're going to say application.", 'start': 1504.987, 'duration': 7.923}, {'end': 1521.673, 'text': "And for the subtype, I'm going to put in a string here and this is going to be octet dash string.", 'start': 1513.55, 'duration': 8.123}, {'end': 1525.354, 'text': 'So make sure you can see both of those there.', 'start': 1522.193, 'duration': 3.161}, {'end': 1530.857, 'text': 'Now by setting the application as the main type and octet stream as the subtype.', 'start': 1525.854, 'duration': 5.003}], 'summary': 'Setting attachment type as application/octet-stream.', 'duration': 25.87, 'max_score': 1504.987, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1504987.jpg'}, {'end': 1578.004, 'src': 'embed', 'start': 1552.41, 'weight': 3, 'content': [{'end': 1560.575, 'text': 'but if we look at the resume, then we can see that we do have this resume.pdf here and we do have that PDF file.', 'start': 1552.41, 'duration': 8.165}, {'end': 1562.075, 'text': 'so that worked well, okay.', 'start': 1560.575, 'duration': 1.5}, {'end': 1566.758, 'text': "so now let's look at a couple more tips here that you might find useful when sending emails.", 'start': 1562.075, 'duration': 4.683}, {'end': 1570.38, 'text': "so first let's say that you want to send emails to multiple people.", 'start': 1566.758, 'duration': 3.622}, {'end': 1571.921, 'text': "that's fairly common now.", 'start': 1570.38, 'duration': 1.541}, {'end': 1578.004, 'text': "in order to do that, it's as simple as passing in a list where we currently have the receiver.", 'start': 1571.921, 'duration': 6.083}], 'summary': 'Demonstrated success in sending resume.pdf and tips for sending emails to multiple recipients.', 'duration': 25.594, 'max_score': 1552.41, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1552410.jpg'}, {'end': 1622.653, 'src': 'embed', 'start': 1594.792, 'weight': 0, 'content': [{'end': 1600.214, 'text': 'And then you can pass in what other email address that you want to send this to.', 'start': 1594.792, 'duration': 5.422}, {'end': 1603.676, 'text': 'So test at example.com or something like that.', 'start': 1600.334, 'duration': 3.342}, {'end': 1610.802, 'text': 'And now when you do the message to, we could pass in that list of contacts.', 'start': 1604.196, 'duration': 6.606}, {'end': 1616.908, 'text': 'Now when I was making this video, I tested this with my email and the email of a friend of mine and it worked well.', 'start': 1611.183, 'duration': 5.725}, {'end': 1622.653, 'text': "It did send emails to both of us, but this isn't how they have it in the Python documentation.", 'start': 1617.589, 'duration': 5.064}], 'summary': "Demonstrated sending emails to multiple addresses, successfully tested with own email and friend's email.", 'duration': 27.861, 'max_score': 1594.792, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1594792.jpg'}, {'end': 1783.803, 'src': 'embed', 'start': 1752.187, 'weight': 1, 'content': [{'end': 1758.591, 'text': "then I'll be sure to add that to my GitHub and leave a link to that in the description section below if you would like to use this as well.", 'start': 1752.187, 'duration': 6.404}, {'end': 1763.975, 'text': "So I'm just going to copy this email here and now go back to the script.", 'start': 1758.971, 'duration': 5.004}, {'end': 1769.797, 'text': "And now let's add that HTML to our email.", 'start': 1764.575, 'duration': 5.222}, {'end': 1777.7, 'text': 'So to do this, I can simply say msg.add,alternative.', 'start': 1770.758, 'duration': 6.942}, {'end': 1783.803, 'text': "And now within add alternative, I'm going to put triple quotes here.", 'start': 1778.221, 'duration': 5.582}], 'summary': 'Demonstrating code for adding html to email using msg.add alternative.', 'duration': 31.616, 'max_score': 1752.187, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1752187.jpg'}], 'start': 1504.987, 'title': 'Python email tips', 'summary': 'Covers how to set attachment type as application/octet-stream in python, sending emails to multiple recipients, including html content, and a demonstration of html email with a styled heading. it also emphasizes the importance of changing the subject when sending an email with an attachment and suggests checking the github repository for the complete script.', 'chapters': [{'end': 1551.99, 'start': 1504.987, 'title': 'Setting attachment type in python', 'summary': 'Explains how to set the attachment type in python as application/octet-stream, a generic bag of bits type, and also highlights the importance of changing the subject when sending an email with an attachment.', 'duration': 47.003, 'highlights': ['The chapter explains how to set the attachment type in Python as application/octet-stream, a generic bag of bits type.', 'The importance of changing the subject when sending an email with an attachment is highlighted.']}, {'end': 1903.852, 'start': 1552.41, 'title': 'Python email tips and html', 'summary': 'Covers tips for sending emails to multiple recipients and including html content in python, along with a demonstration of html email with a styled heading. it also includes a suggestion to check the github repository for the complete script.', 'duration': 351.442, 'highlights': ['The chapter covers tips for sending emails to multiple recipients, including using a list of contacts and creating a comma-separated string from the list, with a successful test of sending emails to multiple recipients.', 'Demonstration of adding HTML content to an email message using the msg.add_alternative method, including a styled heading, with a suggestion to check the GitHub repository for the complete script.', 'Instructions to check the GitHub repository for the complete script and a link to the repository provided in the description section for viewers to access the finished script.', 'Encouragement for viewers to ask questions in the comment section, support the tutorials by liking and sharing the video, and contribute through Patreon, with a link provided in the description section for Patreon support.']}], 'duration': 398.865, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/JRCJ6RtE3xU/pics/JRCJ6RtE3xU1504987.jpg', 'highlights': ['The chapter covers tips for sending emails to multiple recipients, including using a list of contacts and creating a comma-separated string from the list, with a successful test of sending emails to multiple recipients.', 'Demonstration of adding HTML content to an email message using the msg.add_alternative method, including a styled heading, with a suggestion to check the GitHub repository for the complete script.', 'The chapter explains how to set the attachment type in Python as application/octet-stream, a generic bag of bits type.', 'The importance of changing the subject when sending an email with an attachment is highlighted.']}], 'highlights': ['The chapter covers the process of sending emails using Python, focusing on using Gmail and configuring settings, including allowing less secure apps and creating app passwords for two-factor authentication.', 'The tutorial emphasizes the importance of best practices for handling sensitive information, such as using configuration files or environment variables to store sensitive data instead of directly adding it to the Python script.', 'The chapter emphasizes the importance of using environment variables to securely store sensitive information such as email address and password, promoting secure scripting practices.', 'The chapter introduces the use of the SMTP lib module for connecting to the mail server and sending emails using Python.', 'The method of sending a simple plain text email using Python is elucidated as smtp.sendmail, offering a straightforward approach to email communication.', 'The process of creating a simple plain text email using Python is explained, including setting the subject as a header and adding the body of the message, providing insights into the formatting methods.', 'Utilizing the email message class to set up and send messages more efficiently', 'The process of attaching images to an email using a new email message object is explained. Using a new email message object to send the message, changing the subject and body of the message, opening the file, and reading the image data.', 'The chapter covers tips for sending emails to multiple recipients, including using a list of contacts and creating a comma-separated string from the list, with a successful test of sending emails to multiple recipients.', 'Demonstration of adding HTML content to an email message using the msg.add_alternative method, including a styled heading, with a suggestion to check the GitHub repository for the complete script.']}