Automate Gmail Messages Using Python Selenium – Selenium In Hindi

Python Selenium

Automate Gmail Messages Using Python Selenium – Gmail Send karne Ke liye Ham Python Selenium Me Ek Script Likhne Wale Hai, Jisse Gmail Messages Ko Automate Kiya Ja Sakta Hai, ye Script Aapne Hi Bahut Sare Mail Send Kar Sakti hai, Without Any Problem.

Yadi Aapne  HTML Full Course  And CSS Full Course And Python Full Course And PHP Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Automate Gmail Using Python Selenium

Sabse Pahle Aapko Python And Selenium Ko Install And Setup karna Padega, iske liye Aapko Niche Diye Link Par Click Karke Setup Kar Sakte Hai.
Click here for Setup -> Installing Python, Selenium & Pycharm IDE

And Agar Aapko Selenium Ke Bare Me Nhi Pata Hai To, Niche Diye Gaye Link Par Click Karke Iske Bare me Full Jankari Le Sakte Hai -> What is Python Selenium in Hindi

To Ab Start Karte Hai, Automate Gmail Kaise Send Kare Uske Code ke Bare Me.
Sabse Pahle Aapko Necessary Library Ko Import Karna Padega.

# Import the necessary modules
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

Uske Bad Aapko Jo Requirement Variables Hai, Unhe Aapne Hisab se Fill Karna Padega, Jaise Ki Aap Kis Mail se Login Karna Chahte Ho And Kin Email Par Mail Send Karna Chahte Ho.

# Requirement Variables
your_email = "[email protected]"
your_password = "*******"
to_email = ['[email protected]','[email protected]','[email protected]']
subject = "Your_Subject"
message = "This is a test email sent using Selenium and Python."

Ab Aapko Aapne Chrome Driver Ko Setup Karna Padega.

# Set up the driver
driver = webdriver.Chrome(executable_path='your_chrome_driver_path')

Agar Aapko Chrome Driver Ka path set Karna Nhi Aata Hai To Niche Diye Gayi Video Ko Dekh Sakte Hai.

Ab Aapko Gmail Me Login karna Hoga, Uske liye Aap Niche Diye Code Ko Dekh Sakte Hai, Yad Rahe Jo Gmail Hai Wo Time Time name (identifier / Passwd) Variable Ko Value Ko Change Karta Rahta Hai, To Ek Bar name Variable ko Value ko Jarur Check karle gmail input ko inspact Karke.

# Open Gmail
driver.get('https://gmail.com')
driver.maximize_window()

# Log in to your account
time.sleep(2)
username_input = driver.find_element_by_name('identifier')
username_input.send_keys(your_email)
username_input.send_keys(Keys.ENTER)


time.sleep(5)
password_input = driver.find_element_by_name('Passwd')
password_input.send_keys(your_password)
password_input.send_keys(Keys.ENTER)

# Wait for the page to load
driver.implicitly_wait(10)

Ab Niche Jo Code Diya Hai, Wo Compose Button Par Click karke To Email/Subject/message And Send Button Par Click karke Mail Ko Send Karta Hai, Jab Tak Loop End Na Ho Tab Tak.

for i in to_email:
    # Click on the "compose" button to create a new email
    compose_button = driver.find_element_by_xpath('//div[text()="Compose"]')
    compose_button.click()


    # Fill in the email details
    time.sleep(3)
    to_input = driver.find_element_by_xpath('//input[@role="combobox"]')
    to_input.send_keys(i)
    subject_input = driver.find_element_by_name('subjectbox')
    subject_input.send_keys(subject)
    body_input = driver.find_element_by_xpath('//div[@role="textbox"]')
    body_input.send_keys(message)

    # Click the "send" button to send the email
    send_button = driver.find_element_by_xpath('//div[text()="Send"]')
    send_button.click()

    time.sleep(4)

Uske Bad Jab Sari Email Hamari Send Ho Jati hai, To Ham Chrome Ko Ham Close Kar Denge.

# Close the browser
driver.quit()

Ab Tak Hamne Jo Bhi Process Dekha Hai, Wo Hamne Code Ko Split Karke Dekha Hai, Jo Niche Diya Gaya Code Hai, wo Hamara Final Code Hai.
Final Code.

# Import the necessary modules
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time


# Requirement Variables
your_email = "[email protected]"
your_password = "*******"
to_email = ['[email protected]','[email protected]','[email protected]']
subject = "Your_Subject"
message = "This is a test email sent using Selenium and Python."


# Set up the driver
driver = webdriver.Chrome(executable_path='your_chrome_driver_path')

# Open Gmail
driver.get('https://gmail.com')
driver.maximize_window()

# Log in to your account
time.sleep(2)
username_input = driver.find_element_by_name('identifier')
username_input.send_keys(your_email)
username_input.send_keys(Keys.ENTER)


time.sleep(5)
password_input = driver.find_element_by_name('Passwd')
password_input.send_keys(your_password)
password_input.send_keys(Keys.ENTER)



# Wait for the page to load
driver.implicitly_wait(10)

for i in to_email:
    # Click on the "compose" button to create a new email
    compose_button = driver.find_element_by_xpath('//div[text()="Compose"]')
    compose_button.click()


    # Fill in the email details
    time.sleep(3)
    to_input = driver.find_element_by_xpath('//input[@role="combobox"]')
    to_input.send_keys(i)
    subject_input = driver.find_element_by_name('subjectbox')
    subject_input.send_keys(subject)
    body_input = driver.find_element_by_xpath('//div[@role="textbox"]')
    body_input.send_keys(message)

    # Click the "send" button to send the email
    send_button = driver.find_element_by_xpath('//div[text()="Send"]')
    send_button.click()

    time.sleep(4)

# Close the browser
driver.quit()

Leave a Reply

Your email address will not be published. Required fields are marked *