This Python script allows you to send emails using the Simple Mail Transfer Protocol (SMTP). It is configured through a .env
file, providing flexibility in setting up various email parameters.
- Python: Ensure you have Python installed on your machine.
- Dependencies: Install the required dependencies using the following command:
pip install python-dotenv pip install dnspython
- Clone the repository to your local machine.
- Create a virtual environment (optional but recommended):
python -m venv venv
- Activate the virtual environment:
- For Windows:
.\venv\Scripts\activate
- For macOS/Linux:
source venv/bin/activate
- For Windows:
- Create a
.env
file in the root directory with the following content:Replace the placeholder values with your actual SMTP server details, email addresses, and other parameters.SMTPSERVER="your_smtp_server" SMTPSERVERPORT="your_smtp_port" SMTPSERVERUSER="your_smtp_user" SMTPSERVERTOKEN="your_smtp_token" SENDER="your_sender_email" SENDERNAME="your_sender_name" RECIEVER="your_receiver_email" SUBJECT="your_email_subject" CONTENT="your_email_content" REPLYTO="email_adress_replies_go_to"
This is not neccesary, though without it, you will be asked to reenter the details every time.
The SMTP variables are treated seperately from the others, meaning you can chose to preset only the SMTP variables, and manually enter the per-email details every time.
-
Run the script:
python main.py
-
If the script detects a
.env
file, it will load the configurations. Otherwise, it will prompt you to enter the necessary details. -
The script will attempt to send the email, and you will receive a confirmation message if successful.
- If an error occurs during execution, the script will display an error message indicating the issue.
- Ensure that your SMTP server allows the specified sender to send emails.
Feel free to customize the email content and subject in the .env
file according to your needs.