This Python script sends an email using Gmail SMTP. It loads sender credentials and recipient email address from environment variables, and the email content from a file. The script supports sending both plain text and HTML emails.
- Python 3.x installed on your system
- Gmail account for sending emails
- Enable "Less secure app access" or set up an "App password" for Gmail (if using 2-step verification)
-
Clone this repository to your local machine:
git clone https://github.com/AppleBoiy/pymail.git
-
Install the required Python packages:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.envfile in the project directory and add the following variables:EMAIL_SENDER=your_email@gmail.com PASSWORD_SENDER=your_gmail_password_or_app_password RECEIVER_EMAIL=recipient_email@example.comReplace
your_email@gmail.comwith your Gmail email address,your_gmail_password_or_app_passwordwith your Gmail password or app password, andrecipient_email@example.comwith the recipient's email address.
Run the script main.py to send the email:
python main.py- Modify the
payload.htmlfile to customize the email content. - Adjust the logging configuration in the script as needed.
- Extend the script with additional features like attachments or multiple recipients.