A simple Python module to send emails easily.
You can install this package directly from GitHub using pip:
pip install git+https://github.com/lopezrbn/python_mailer.gitAlternatively, if you want to include it in your requirements.txt file, add the following line:
git+https://github.com/lopezrbn/python_mailer.git
💡 Note: If you prefer using SSH instead of HTTPS, you can use:
git+ssh://git@github.com/rlopez-bigdecisions/python_mailer.git
Make sure your system has access to Git and that any authentication requirements (e.g., SSH keys) are configured appropriately.
After installation, you can import and use the send_email function:
from python_mailer import send_email
send_email(
email_to="example@example.com",
subject="Test Email",
message="Hello, this is a test email!",
)The function send_email() supports multiple methods to provide email credentials:
Define an environment variable with the path to your credentials JSON file:
export PATH_EMAIL_CREDENTIALS="/path/to/email_credentials.json"Your JSON file must have the following structure:
{
"email_from": "your_email@example.com",
"password": "your_password_here"
}You can also optionally include a default recipient:
{
"email_from": "your_email@example.com",
"password": "your_password_here",
"email_to": "recipient@example.com"
}If no credentials argument is passed to the function, it will automatically attempt to load the path from this variable.
send_email(
credentials="/path/to/email_credentials.json",
subject="Hello",
message="This is a test"
)send_email(
credentials={
"email_from": "your_email@example.com",
"password": "your_password_here",
"email_to": "recipient@example.com" # Optional
},
subject="Hello",
message="This is a test"
)- The
email_toparameter can be passed directly to the function. - If it is not provided, and the loaded credentials dictionary includes an
"email_to"field, that value will be used as the recipient address. - If neither is present, the function will raise a
ValueError.
Do not commit any credentials file to your public repositories.
Make sure to include your credentials file (e.g. .env, .json) in .gitignore:
*.json
.envThis project is licensed under the MIT License. See the LICENSE file for details.
- Rubén López Pérez
- Data Scientist
- lopezrbn@gmail.com