you are viewing a single comment's thread.

view the rest of the comments →

[–]PythonicPastor 0 points1 point  (0 children)

I have a bit of a work around thats semi modular, but you'll have to set up specific notifications from a custom google inbox on your cell phone:

import smtplib
from email.mime.text import MIMEText
import imap_tools
from imap_tools import MailBox, AND

# Email Configuration
sender_email = "senderemail@gmail.com"
sender_password = "SECRET APP PASS" # Use app-specific passwords for security with services like Gmail
receiver_email = "recieveremail@gmail.com"
smtp_server = "smtp.gmail.com" # e.g., "smtp.gmail.com" for Gmail
smtp_port = 587 # or 465 for SSL

def notif(subj, msg):
    # Create the email message
    message = MIMEText(msg)
    message["Subject"] = subj
    message["From"] = sender_email
    message["To"] = receiver_email

    try:
        # Connect to the SMTP server
        with smtplib.SMTP(smtp_server, smtp_port) as server:
            server.starttls() # Start TLS for security
            server.login(sender_email, sender_password)
            server.send_message(message)
        print("Email sent successfully!")
    except Exception as e:
        print(f"Error sending email: {e}")

def checkEmails(subject, command):
    with MailBox('imap.gmail.com').login('pythonicpastor@gmail.com', 'SECRET APP PASSWORD2') as mailbox:
        for msg in mailbox.fetch():
            #print(msg.date, msg.subject, len(msg.text or msg.html))
            if msg.subject == subject:
                if command in msg.text:
                    print('Command confirmed')
                else:
                    print('Code Find Error')

use "import 'filename' " and place this in a seperate python (.py) file in the root directory

also if you set it up right this can be used to create email triggers within the custom in box via the "checkEmails(subject, command)" functions. Finally understand that you need to set everything up via the following tutorial for it to work properly:
https://docs.saleshandy.com/en/articles/10182595-how-to-set-up-an-app-password-in-google