Grande email checking

Here's a sample email checking script in Python using the smtplib and email libraries:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_email(subject, message, from_addr, to_addr, password):
    msg = MIMEMultipart()
    msg['From'] = from_addr
    msg['To'] = to_addr
    msg['Subject'] = subject

    body = message
    msg.attach(MIMEText(body, 'plain'))

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(from_addr, password)
    text = msg.as_string()
    server.sendmail(from_addr, to_addr, text)
    server.quit()

subject = "Grande Email Checking"
message = "Hello, this is a test email from Python."
from_addr = "[email protected]"
to_addr = "[email protected]"
password = "your_password"

send_email(subject, message, from_addr, to_addr, password)

This script sends an email with a subject and message from a specified sender address to a recipient address. You'll need to replace the placeholders ([email protected], [email protected], and your_password) with your actual Gmail address, recipient's email address, and your Gmail password.

Please note that you need to allow less secure apps to access your Gmail account. You can do this by going to your Google Account settings and enabling the "Less secure app access" option.

Also, be aware that storing your password in plain text is not recommended for security reasons. You should consider using a more secure method to store and retrieve your password.

For more advanced email checking, you can use a library like imaplib to connect to an IMAP server and retrieve emails. Here's a basic example:

import imaplib
import email

def check_email(username, password):
    mail = imaplib.IMAP4_SSL('imap.gmail.com')
    mail.login(username, password)
    mail.select('inbox')

    status, data = mail.search(None, 'ALL')
    mail_ids = []

    for block in data:
        mail_ids += block.split()

    for i in mail_ids:
        status, data = mail.fetch(i, '(RFC822)')
        for response_part in data:
            if isinstance(response_part, tuple):
                message = email.message_from_bytes(response_part[1])
                mail_from = message['from']
                mail_subject = message['subject']

                if mail_from and mail_subject:
                    print(f"From: {mail_from}, Subject: {mail_subject}")

    mail.close()
    mail.logout()

username = "[email protected]"
password = "your_password"

check_email(username, password)

This script connects to your Gmail IMAP server, logs in, and retrieves all emails in your inbox. It then prints the sender and subject of each email. Again, you'll need to replace the placeholders with your actual Gmail address and password.

Remember to handle exceptions and errors properly in your production code.