An email and AI agent that helps one to create masages
This app allows you to send emails programmatically via Gmail using the SMTP protocol. The email content, subject, and recipient are dynamically generated and sent using a Gmail account that requires an app-specific password for enhanced security.
- Send Emails: Automatically send emails with custom subject and body.
- Environment Variables: Securely store Gmail credentials using a
.env
file. - SMTP over SSL: Sends emails via Gmail’s SMTP server with SSL encryption.
- Error Handling: Includes error handling to catch and display any login or sending issues.
- Python 3.x
- Gmail account with 2-Step Verification enabled and an app password generated
- Libraries:
smtplib
(Python Standard Library)email
(Python Standard Library)python-dotenv
-
Clone the repository:
git clone https://github.com/yourusername/email-sending-app.git cd email-sending-app
-
Create a virtual environment (Optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts�ctivate`
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the root of your project and add the following environment variables:SENDER_EMAIL=[email protected] GMAIL_APP_PASSWORD=your-app-password
You can generate an app password by following this guide if you have 2-Step Verification enabled on your Gmail account.
-
Run the app: Once everything is set up, you can run the app by executing the Jupyter notebook or Python script in your environment.
-
Import necessary libraries and load environment variables:
In the notebook, the code reads credentials stored in the
.env
file securely:import smtplib from email.message import EmailMessage from dotenv import load_dotenv import os load_dotenv() # Load environment variables from .env file SENDER_EMAIL = os.getenv('SENDER_EMAIL') GMAIL_APP_PASSWORD = os.getenv('GMAIL_APP_PASSWORD')
-
Define email generation and sending functions:
generate_email(subject, body)
: Creates a simple email body using the subject and body text.send_email(to_email, subject, body)
: Logs into Gmail’s SMTP server and sends the email.
-
Send an email:
Example of sending an email:
email_body = generate_email("Meeting Request", "Requesting a meeting on Tuesday at 10 AM.") send_email("[email protected]", "Meeting Request", email_body)
- Replace
[email protected]
with the desired recipient's email address. - Customize the subject and body as needed.
- Replace
After successfully sending the email, you should see:
Email sent successfully!
If there is an error, it will be displayed with details, such as authentication issues or server connection failures.
- SMTP Authentication Error: If you encounter an authentication error, ensure that you are using an app password and not your regular Gmail password. If you haven't generated one yet, follow these steps.
- Missing Environment Variables: Make sure the
.env
file is properly configured and located in the same directory as your notebook.
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please reach out to [[email protected]].