This is a Python application that demonstrates how to send emails using the SMTP protocol. It includes a EmailClient class that encapsulates the functionality for connecting to an SMTP server, logging in, sending emails, and closing the connection.
- Connect to an SMTP server securely using STARTTLS.
- Login to the SMTP server with email credentials.
- Send emails with customizable subject, body, and recipient(s).
- Gracefully handle errors during connection, login, and email sending.
-
Clone the repository to your local machine:
git clone https://github.com/mtauha/automate-emails.git
-
Navigate to the project directory:
cd Automate-Emails -
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.envfile in the project root directory and add your email credentials and SMTP server information:EMAIL=[email protected] PASSWD=your_password SMTP_SERVER=smtp.example.com SMTP_PORT=587
-
Create an instance of the
EmailClientclass in your Python script:from EmailClient import EmailClient instance = EmailClient()
-
Connect to the SMTP server:
instance.connect()
-
Login to the SMTP server:
instance.login()
If you are experiencing this error please visit this link:
Username and Password not accepted. For more information, go to\n5.7.8 https://support.google.com/mail/?p=BadCredentials -
Send an email:
subject = "Testing Script"
body = "This is a test email."
to_email = "[email protected]"
instance.send(subject, body, to_email)-
Close the connection when done:
instance.close()
To run the Python Email Client application using Docker, follow these steps:
-
Build the Docker image from the project directory:
docker build -t Automate-Emails . -
Run a Docker container from the created image:
docker run -it --rm --env-file .env Automate-Emails
Replace
.envwith the path to your environment file containing email credentials and SMTP server information.
This will start the Python Email Client application inside a Docker container, and you should see the output in the terminal indicating the status of the email sending process.
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
This project is licensed under the MIT License.