-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
1 addition
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1 @@ | ||
import imaplib | ||
import email | ||
import os | ||
import subprocess | ||
|
||
# Email configuration | ||
EMAIL_HOST = 'imap.gmail.com' | ||
EMAIL_USERNAME = '[email protected]' | ||
EMAIL_PASSWORD = 'nthuxtqxmkrdglyl' | ||
SPECIFIC_USER_EMAIL = '[email protected]' # Change to the specific user's email address | ||
|
||
def mark_email_as_unread(mail, email_id): | ||
mail.store(email_id, '-FLAGS', '\Seen') # Mark the email as unread | ||
|
||
def check_emails(): | ||
# Connect to the email server | ||
mail = imaplib.IMAP4_SSL(EMAIL_HOST) | ||
mail.login(EMAIL_USERNAME, EMAIL_PASSWORD) | ||
mail.select("inbox") | ||
|
||
# Search for emails with the specified criteria | ||
status, email_ids = mail.search(None, f'(UNSEEN) (FROM "{SPECIFIC_USER_EMAIL}") (SUBJECT "shutdown" OR SUBJECT "logout" OR SUBJECT "restart")') | ||
|
||
if status == 'OK': | ||
email_id_list = email_ids[0].split() | ||
for email_id in email_id_list: | ||
# Fetch the email by ID | ||
status, email_data = mail.fetch(email_id, '(RFC822)') | ||
if status == 'OK': | ||
msg = email.message_from_bytes(email_data[0][1]) | ||
subject = msg['subject'].lower() | ||
|
||
# Perform system actions based on email subject | ||
if "shutdown" in subject: | ||
os.system("shutdown /s /t 1") # Shutdown | ||
elif "logout" in subject: | ||
os.system("shutdown -l") # Log out | ||
elif "restart" in subject: | ||
os.system("shutdown /r /t 1") # Restart | ||
|
||
# If the email is not from the specified user, mark it as unread | ||
if msg['from'] != SPECIFIC_USER_EMAIL: | ||
mark_email_as_unread(mail, email_id) | ||
|
||
# Close the connection | ||
mail.logout() | ||
|
||
if __name__ == "__main__": | ||
check_emails() | ||
ok |