Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A robust SMTP mailer library, with async mail send features built-in using Threads and Multiprocessing. Zero PyPI (production) dependencies.
Install with pip install emailee
.
Send a simple text email
import emailee
my_email = emailee.Emailee()
my_email.sender("john.smith@fakeemail.com")
my_email.subject("Test email")
my_email.msgContent("some poorly formatted raw text")
my_email.sendTo(["jill.smith@fakeemail.com"])
my_email.server("smtp.fakeemail.com")
if my_email.ready():
my_email.send()
Send multiple asyncronous emails
import emailee
emails_list = [{...}]
server_dict = {...}
emails = emailee.AsyncThreads(emails_list, server_dict, outputFile='output.txt')
There are only three classes exposed to the user of this library, Emailee
, AsyncThreads
and AsyncMP
. The latter two utilise the Emailee class to send emails via the Threading or Multiprocessing async APIs respectively.
If you have used the smtplib
and email
libraries in the past, you may of found how difficult it is getting the email logic set up properly to handle attachments and different sending scenarios. All customisations are built into Emailee, which takes the guess work out of how to configure.
The following methods are exposed to the user:
It's a good idea to use both of these to replicate your email, so users who can't read HTML emails can read your fallback raw text email. Look online for HTML email generators
Returns True if the minimal fields to send an email have been set.
Returns True if successful, does not guarantee email was delivered, just sent.
Print class function, will print a dictionary of email metadata, useful for testing and debugging.
Both async classes are very similar in their function and both require emails and server config in the exact same format:
mail_list = [
{
'sender': sender # see Emailee.sender()
'replyTo': replyTo # see Emailee.sender()
'subject': email_subject # see Emailee.subject()
'msgText': raw_text_message # see Emailee.msgContent()
'msgHTML': HTML_formatted_message # see Emailee.msgContent()
'to': list_of_to_emails # see Emailee.sendTo()
'cc': list_of_cc_emails # see Emailee.sendTo()
'bcc': list_of_bcc_emails # see Emailee.sendTo()
'ignoreErrors': True # see Emailee.sendTo()
'attachmentFiles': list_of_attachment_file_paths # see Emailee.attachmentFiles()
},
{...},
]
server_dict = {
'smtpServer': SMTP_server # see Emailee.server()
'port': port_number # see Emailee.server()
'SSLTLS': 'TLS' # see Emailee.server()
'authUsername': authenticated_username # see Emailee.server()
'authPassword': authenticated_password # see Emailee.server()
}
AsyncThreads uses the threading API to enable asyncronous sending of email. Threading only utilises the same CPU core that the Python program is currently running on, so it can only maximise a single core usage, but the benefits are you can throttle how many threads are allowed to run concurrently and it has a lower overhead compared to AsyncMP
.
AsyncMP uses the multiprocessing API to enable asyncronous sending of email. Multiprocessing utilises all CPU cores of the system the Python program is running on, but does not allow throttling, so you run the risk of maxing out your CPU and RAM, slowing down your system.
Upon completion of either async class, you can call the emailReport()
method to return a metadata list of all emails sent.
This won't work if an exception is thrown during the sending process, hence the outputFile requirement.
The output file will be written to after each successful email send so you can analyse against emailReport()
or see who received emails before a thrown exception or manual cancellation of the sending process.
Emailee is built with poetry, tested with pytest, tox and coverage, type checked with mypy and formatted with black.
Clone the repo, cd
into it and run poetry install
Clone the repo, cd
into it, build and run a new virtual environment, then open the pyproject.toml
file and pip install
all packages listed under [tool.poetry.dev-dependencies]
To successfully run local tests you will need to rename tests/example.test.env.toml
to tests/test.env.toml
and modify the config inside the file to contain valid email and SMTP server connection data.
Testing and coverage can then be run with pytest --cov-report term-missing --cov=emailee tests
Tox can be used to run pytest against all support Python environments. Open tox.ini
and check if you have all versions of Python installed listed under envlist.
Run pre-commit install
to install the pre-commit hooks in the .pre-commit-config.yaml
file. Then run pre-commit run --all-files
to auto-check every file for issues.
Feel free to send me any changes or feedback.
Thanks for reading :)
:envelope: :envelope: :envelope: :envelope: :envelope:
FAQs
A robust smtp email send tool, with asyncronous send capability
We found that emailee demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.