Skip to content

Instantly share code, notes, and snippets.

@amar061996
Created February 20, 2016 14:19
Show Gist options
  • Select an option

  • Save amar061996/d4dd744acba1c295cb9a to your computer and use it in GitHub Desktop.

Select an option

Save amar061996/d4dd744acba1c295cb9a to your computer and use it in GitHub Desktop.
bot to log into gmail account and compose and send mail using selenium webdriver
from selenium import webdriver
def send_mail(username,password,to,subject,text):
url="https://mail.google.com"
br=webdriver.Firefox()
br.get(url)
br.find_element_by_id("Email").clear()
br.find_element_by_id("Email").send_keys(username)
br.find_element_by_id("next").click()
br.implicitly_wait(5)
br.find_element_by_id("Passwd").clear()
br.find_element_by_id("Passwd").send_keys(password)
br.find_element_by_id("signIn").click()
br.implicitly_wait(60)
br.find_element_by_css_selector(".T-I-KE").click()
br.implicitly_wait(30)
br.find_element_by_id(":n4").clear()
br.find_element_by_id(":n4").send_keys(to)
br.find_element_by_id(":mo").clear()
br.find_element_by_id(":mo").send_keys(subject)
br.find_element_by_id(":nt").clear()
br.find_element_by_id(":nt").send_keys(text)
br.find_element_by_id(":me").click()
user=raw_input("Enter your gmail id: ")
pasd=raw_input("Enter the password: ")
dest=raw_input("Enter the destination Email id: ")
sub=raw_input("ENter the subject: ")
msg=raw_input("Enter the message: ")
send_mail(user,pasd,dest,sub,msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment