├── .gitignore ├── README.md ├── LICENSE └── responder.py /.gitignore: -------------------------------------------------------------------------------- 1 | .pyc 2 | .idea 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Gmail Autoresponder 2 | 3 | A simple Autoresponder for Gmail that responds mails based on sender. It has been written in Python by using Selenium Library. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Adnan Siddiqi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /responder.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from time import sleep 3 | 4 | driver = None 5 | driver = webdriver.Firefox() 6 | 7 | SENDER = '' 8 | GMAIL_USER = '' 9 | GMAIL_PASSWORD = '' 10 | MESSAGE = 'I will get back to you soon. \n Thanks' 11 | MESSAGE = 'I will get back to you soon. \n Thanks' 12 | 13 | 14 | def access_gmail(): 15 | try: 16 | driver.get('http://gmail.com') 17 | sleep(5) 18 | # Go thru messages list 19 | m = driver.find_elements_by_css_selector('.UI table > tbody > tr') 20 | 21 | for a in m: 22 | if SENDER.lower() in a.text: 23 | a.click() 24 | break 25 | 26 | # take rest 27 | sleep(5) 28 | reply = driver.find_element_by_css_selector('.amn > span') 29 | sleep(5) 30 | if reply: 31 | reply.click() 32 | sleep(1) 33 | 34 | # Access editor to write response 35 | editable = driver.find_element_by_css_selector('.editable') 36 | if editable: 37 | editable.click() 38 | editable.send_keys(MESSAGE) 39 | 40 | send = driver.find_elements_by_xpath('//div[@role="button"]') 41 | for s in send: 42 | if s.text.strip() == 'Send': 43 | s.click() 44 | 45 | except Exception as ex: 46 | print(str(ex)) 47 | finally: 48 | return True 49 | 50 | 51 | def login_google(): 52 | is_logged_in = False 53 | google_login = 'https://accounts.google.com/Login#identifier' 54 | 55 | try: 56 | driver.get(google_login) 57 | sleep(5) 58 | html = driver.page_source.strip() 59 | 60 | # email box 61 | user_name = driver.find_element_by_id('Email') 62 | if user_name: 63 | user_name.send_keys(GMAIL_USER) 64 | 65 | next = driver.find_element_by_id('next') 66 | if next: 67 | next.click() 68 | 69 | # give em rest 70 | sleep(5) 71 | 72 | # now enter passwd 73 | user_pass = driver.find_element_by_id('Passwd') 74 | if user_pass: 75 | user_pass.send_keys(GMAIL_PASSWORD) 76 | 77 | # rest again 78 | sleep(3) 79 | 80 | sign_in = driver.find_element_by_id('signIn') 81 | if sign_in: 82 | sign_in.click() 83 | 84 | # rest again 85 | sleep(3) 86 | is_logged_in = True 87 | 88 | except Exception as ex: 89 | print(str(ex)) 90 | is_logged_in = False 91 | finally: 92 | return is_logged_in 93 | 94 | 95 | if __name__ == '__main__': 96 | r_log = login_google() 97 | if r_log: 98 | print('Yay') 99 | access_gmail() 100 | else: 101 | print('Boo!!!') 102 | 103 | if driver is not None: 104 | driver.quit() 105 | 106 | print('Done') 107 | --------------------------------------------------------------------------------