A collection of useful scripts and tools for server management and automation. Currently the sole module focuses on sending emails with optional attachments via SMTP. It is designed to be secure, flexible, and easy to use, leveraging environment variables for sensitive information and providing command-line arguments for email configuration.
- SMTP Connection: Uses the
smtpliblibrary to handle SMTP connections and send emails. - Environment Variables: Utilizes environment variables for sensitive information like SMTP server details and email account credentials.
- MIME Emails: Constructs MIME-compliant email messages, allowing for plain text bodies and file attachments.
- Command-Line Arguments: Provides flexibility for email configuration through command-line arguments.
- Python: Ensure you have Python 3.6 or higher installed. Download Python
- pip: Python package installer, usually comes with Python. Install pip
- pipenv: Python dependency management tool. Install via:
pip install pipenv
- smtplib: Built-in Python library for sending emails via SMTP.
- socket: Built-in Python library for networking and hostname resolution.
- argparse: Built-in Python library for parsing command-line arguments.
- os: Built-in Python library for interacting with the operating system.
- email.mime: Built-in Python libraries for constructing MIME-compliant emails.
- dotenv: External library for loading environment variables from a
.envfile. Install via:pipenv install python-dotenv
-
Clone the repository:
git clone https://github.com/soupsoftware/server_tools.git cd server_tools -
Install dependencies:
pipenv install
-
Activate the virtual environment:
pipenv shell
-
Create a
.envfile in the project directory and add your SMTP server details and email credentials:SMTP_SERVER=smtp-mail.outlook.com SMTP_PORT=587 EMAIL_ACCOUNT=your_email@example.com EMAIL_PASSWORD=your_password
Run the script with the required command-line arguments to send an email with or without attachments:
python send_email.py -e your_email@example.com -p your_password -r recipient@example.com -s "Test Subject" -b "This is a test email." -a /path/to/file1 /path/to/file2