Efficiently managing our Gmail inbox is vital in today's fast-paced digital landscape. Python enthusiasts can take advantage of the powerful smtplib library to automate their Gmail workflows and optimize productivity. In this article, we will explore how leveraging Python with smtplib can revolutionize the way we interact with Gmail, streamlining communication and organizing our inbox effectively.
- Sign in to Gmail: Ensure you are signed in to your Gmail account using your email address and password.
- Go to Google Account Settings: Click on your profile picture in the top-right corner of the Gmail interface and then select "Manage your Google Account." This will take you to your Google Account settings page.
- Navigate to Security: In your Google Account settings, click on the "Security" tab on the left-hand side.
- Turn on 2-Step Verification: Under the "Signing in to Google" section, find the "2-Step Verification" option. Click on "Get started" and follow the prompts to set up 2-step verification.
- Verify Your Identity: Google will ask you to enter your password to verify your identity.
- Choose 2nd Step Verification Method: Select a method for receiving verification codes. You can choose between "Text message," "Voice call," or "Google prompt" to get codes on your phone.
- Receive Verification Code: Once you've selected a method, you'll receive a verification code on your phone. Enter the code to confirm and activate 2-step verification.
- Generate App Password: If you want to use Gmail with applications that don't support 2-step verification, such as email clients, you'll need to generate an app password. In the Security settings, click on "App passwords," select the app and device type, and click "Generate." Use this app password in the application where you can't use 2-step verification.
- smtplib is a built-in Python library that allows for simple mail transfer protocol (SMTP) communication, facilitating email functionality within Python scripts.
- It enables sending email messages from your Python program to an SMTP server, which then forwards the email to the recipient's mail server.
- smtplib provides a straightforward interface to send plain text or HTML-formatted email messages.
- With smtplib, you can easily connect to an SMTP server, authenticate using credentials, and send emails programmatically.
- Install smtplib using pip command
pip install secure-smtplib
import smtplib
host = "smtp.gmail.com"
port = 587
from_mail = "[email protected]"
to_mail = input("Receiver gmail : ")
password = "paste the 16 letter code you copied without space"
msg = """Subject: Testing Mail
Hi Bro,
This email is sent using python
Thanks"""
smtp = smtplib.SMTP(host, port)
status_code, response = smtp.ehlo()
print(f"[*] Echoing the server: {status_code} {response}")
status_code, response = smtp.starttls()
print(f"[*] Starting TLS connection : {status_code} {response}")
status_code, response = smtp.login(from_mail, password)
print(f"[*] Logging in : {status_code} {response}")
smtp.sendmail(from_mail, to_mail, msg)
print("Mail Sent Successfully!")
smtp.quit()
- Pywhatkit is a Python library that simplifies WhatsApp automation.
- It enables users to send WhatsApp messages programmatically using Python.
- The library allows for the scheduling of WhatsApp messages at specific times.
- It can play YouTube videos by providing the video's URL or search keywords.
- Pywhatkit is easy to use with straightforward functions, making it suitable for beginners and experienced developers alike.
- Install pywhatkit using pip command
import pywhatki
pywhatkit.send_mail("[email protected]", "your passcode e.g ubhfierxxlnaykcw", "Subject", "Hello Pra!, Are you all right?", "your friend's mail you want to send mail")t
- Pywhatkit's send_mail() function provides a simple way to send emails programmatically using Python.
- By using this function, you can automate the process of sending emails to desired recipients.
- The send_mail() function requires your Gmail credentials (email and passcode) to authenticate and send the email on your behalf.
- It allows you to customize the email subject and body with the message you want to convey.
- With Pywhatkit, you can streamline email communications and integrate email functionalities into your Python applications.
- Remember to use this function responsibly and keep your Gmail credentials secure to maintain the privacy and security of your account.
I hope this article will be useful for you and that you learned something new Please, feel free to drop any questions in the comments below. I would be happy to answer them.