0

This is my python 3 scripts that Send ScreenShoot to My Mail .Now i want that code send mail to me after a specific interval of time with updated screenshoot continus

from _multiprocessing import send
from typing import BinaryIO

from PIL import ImageGrab

snapshot = ImageGrab.grab()  # Take snap
file = "scr.jpg"
snapshot.save(file)
import base64, os

f: BinaryIO = open('scr.jpg', 'rb')  # Open file in binary mode
data = f.read()
data = base64.b64encode(data)  # Convert binary to base 64
f.close()
os.remove(file)

import smtplib

s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
# [!]Remember! You need to enable 'Allow less secure apps' in your #google account
# Enter your gmail username and password
s.login("zainali90900666@gmail.com", "password")

# message to be sent
message = data  # data variable has the base64 string of screenshot

# Sender email, recipient email
s.sendmail("zainali90900666@gmail.com", "zainali90900666@gmail.com", message)
Dharman
  • 30,962
  • 25
  • 85
  • 135
emma juila
  • 147
  • 1
  • 1
  • 11
  • How about a `while` loop and `time.sleep(some_number_here)`? – mechanical_meat May 23 '20 at 05:38
  • can you pls show how my code look like after that – emma juila May 23 '20 at 05:39
  • mean to say where to put that lines – emma juila May 23 '20 at 05:40
  • 2
    It appears that you have posted sensitive/private information. Please reset your passwords and/or revoke API keys and tokens, as they are considered compromised when posted on the internet. If personally-identifiable information was posted, please [edit] out the info then flag your post for a moderator to redact the revisions. – Samuel Liew May 24 '20 at 11:23
  • Hopefully a moderator has already redacted those sensitive info (by viewing the revision history). So there is no need, and one should not, vandalize one's post. – user12986714 May 24 '20 at 16:34
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](//meta.stackexchange.com/q/5221) – Dharman May 24 '20 at 16:36
  • Use the flag option to ask moderators to remove the personal information from your post. – Dharman May 24 '20 at 16:37
  • oky got it will do that – emma juila May 24 '20 at 16:39

1 Answers1

0

You can achieve that with a while loop

from _multiprocessing import send
from typing import BinaryIO
import time
import base64, os

from PIL import ImageGrab

def getSnap(fileName):  
    snapshot = ImageGrab.grab()  # Take snap
    snapshot.save(fileName)

    f: BinaryIO = open(fileName, 'rb')  # Open file in binary mode
    data = f.read()
    data = base64.b64encode(data)  # Convert binary to base 64
    f.close()
    os.remove(file)

import smtplib

s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
# [!]Remember! You need to enable 'Allow less secure apps' in your #google account
# Enter your gmail username and password
s.login("zainali90900666@gmail.com", "password")

n = 0
while(True):
    # message to be sent
    message = data  # data variable has the base64 string of screenshot

    # Sender email, recipient email
    s.sendmail("zainali90900666@gmail.com", "zainali90900666@gmail.com", message)

    n += 1
    getSnap('email'+n+'.jpg')
    time.sleep(3) # wait 3 seconds before sending each email
WyattBlue
  • 591
  • 1
  • 5
  • 21