Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Python SMTP service using aiosmtpd that relays through Azure Email Communication Service
Source: https://github.com/LearningToPi/azure_smtp_relay PyPi: https://pypi.org/project/azure-smtp-relay/ Homepage: https://www.learningtopi.com/python-modules-applications/azure_smtp_relay/
This Dockerfile is based on the azure_smtp_relay Python3 package available on PyPi or GitHub.
The azure_smtp_relay was born out of the change in Azure that blocks outbound SMTP unless you have an Enterprise agreement with Azure to specifically allow outbound SMTP. (See Microsoft's documentation for more information: https://learn.microsoft.com/en-us/azure/virtual-network/troubleshoot-outbound-smtp-connectivity)
Previously I had used a VM running in Azure to relay SMTP messages from systems in my home lab (which also couldn't send direct due to ISP restrictions on outbound SMTP). Now that Microsoft ALSO blocks SMTP an alternative was needed.
azure_smtp_relay uses the Azure Communication Service (https://azure.microsoft.com/en-us/products/communication-services) to foward email from internal systems. This service acts as an SMTP server to receive inbound email, then forwards the message through the Azure Communication Service which forwards to the appropriate mail server.
** Please see the Azure_Setup.md () doc for detailed setup of Azure.
The Azure Communication Service accepts email only from domains that have been verified. You MUST have access to update DNS records of the domain to configure. You will need to create a TXT record for Azure to verify the domain. Ideally you will also need to create SPF and DKIM records to minimize the chance of your messages being marked as spam.
** Azure will handle DKIM certificates, you only need to configure DNS records which will be provided for you.
Azure will only allow emails that are FROM specific addresses. An email address of 'DoNotReply@...com' will be created in the service automatically. Additional addresses can be added. Multiple domains can also be registered with the communication service, however the azure_smtp_relay app will only use one.
Azure supports multiple methods of authentication for the Azure Communication service. For simplicity, we support two methods with the azure_smtp_relay application:
Azure auto generates two keys that can be used to authenticate to the endpoint. Only two keys are supported for the service. The intent is to allow rotation of 1 key while the other is in operation. Key based authentication is useful in limited use situations. Service Principals are recommended as more than one account can be created to allow access to the Azure Communication Service.
A service principal is more complicated to configure, but allows multiple accounts to be used with the service simultaneously. A service principal is essentially a service account with a generated password.
Please see the Azure_Setup.md () for detailed setup instructions.
After the service account is created in Microsoft Entra ID (formerly Azure AD) the service account needs to be granted access to use the Azure Commnication service.
THe configuration file used is a ".toml" file. If you are unfamiliar, this is a similar format to a Windows .INI file.
The "config.toml" file consists of 3 sections:
The [azure] section is REQUIRED and MUST contain either a key (if using Key based authentication) --OR-- a tenant_id, client_id and client_secret (if using a service principal). The URL for the Azure Communication service is also required.
[azure]
endpoint = "https://.....unitedstates.communication.azure.com"
tenant_id = '........-....-....-....-............'
client_id = '........-....-....-....-............'
client_secret = "........"
The [relay] section at minimum must contain the from address, domain list, and list of subnets to allow relay from and from_address are required. The remaining are additional options that can be provided.
[relay]
address = 0.0.0.0
port = 10025
from_address = DoNotReply@yourdomain.com
domains = yourdomain.com,yourdomain2.com
subnets = 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
log_level = INFO
max_queue_length = 100
enable_send_log = True
retain_log_days = 3
send_queue_max_age = 43200
send_timeout = 30
message_retry = 3
message_retry_delay = 3600
The [server] section includes options to manage the service itself. Presently only two options are available:
[server]
server_restart_per_hour = 5
server_restart_email = admin@yourdomain.com
The azure_smtp_relay module is also designed to use command line parameters either in addition or in place of the TOML file. Azure credentials may be passed via command line parameter, however it is recommended to use the TOML file for security reasons. The following is an example of running from the CLI:
NOTE: Make sure to create a venv and install the require packages from the requirements.txt file.
(venv) $ python3 -m azure_smtp_relay --help
usage: python3 -m azure_smtp_relay [-h] [--address ADDRESS] [--port PORT] [--from-address FROM_ADDRESS] [--domains DOMAINS] [--subnets SUBNETS] [--log-level LOG_LEVEL] [--max-queue-length MAX_QUEUE_LENGTH]
[--enable-send-log ENABLE_SEND_LOG] [--retain-log-days RETAIN_LOG_DAYS] [--send-queue-max-age SEND_QUEUE_MAX_AGE] [--send-timeout SEND_TIMEOUT] [--message-retry MESSAGE_RETRY]
[--message-retry-delay MESSAGE_RETRY_DELAY] [--server-restart-per-hour SERVER_RESTART_PER_HOUR] [--server-restart-email SERVER_RESTART_EMAIL] [--endpoint ENDPOINT] [--key KEY]
[--tenant-id TENANT_ID] [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] [--config CONFIG] [--print-version]
Python SMTP service using aiosmtpd that relay's through Azure Email Communication Service
options:
-h, --help show this help message and exit
--address ADDRESS [relay] (DEFAULT: 0.0.0.0) IP address to listen on. By default uses 0.0.0.0 (all addresses)
--port PORT [relay] (DEFAULT: 10025) TCP port number to listen on for incoming SMTP traffic. By default uses port 25.
--from-address FROM_ADDRESS
[relay] Email address to use as From address. Must be authorized in Azure communication service.
--domains DOMAINS [relay] Domains to accept email for. Domains should be a comma separated list. i.e. none.com,onmicrosoft.com
--subnets SUBNETS [relay] Subnets that should be allowed to relay email. Subnets should be a comma separated list. i.e. 192.168.0.0/16,10.0.0.0/8
--log-level LOG_LEVEL
[relay] Logging level for the service. Defaults to INFO.
--max-queue-length MAX_QUEUE_LENGTH
[relay] (DEFAULT: 100) Maximum number of messages to retain in the queue before discarding.
--enable-send-log ENABLE_SEND_LOG
[relay] (DEFAULT: True) Enable the send log.
--retain-log-days RETAIN_LOG_DAYS
[relay] (DEFAULT: 72) Number of days to retain log data
--send-queue-max-age SEND_QUEUE_MAX_AGE
[relay] (DEFAULT: 43200) 'Maximum number of seconds to hold a message in the queue.
--send-timeout SEND_TIMEOUT
[relay] (DEFAULT: 30) Timeout for sending to the Azure communication service.
--message-retry MESSAGE_RETRY
[relay] (DEFAULT: 3) Number of times to retry a message before discarding.
--message-retry-delay MESSAGE_RETRY_DELAY
[relay] (DEFAULT: 3600) Number of seconds before retrying a message.
--server-restart-per-hour SERVER_RESTART_PER_HOUR
[server] (DEFAULT: 5) Maximum number of times to attempt restarting the server if a failure occurs.
--server-restart-email SERVER_RESTART_EMAIL
[server] Email address to send a report to after a server restarts after a failure.
--endpoint ENDPOINT [azure] Azure Communication Endpoint URL. See README.md for help finding.
--key KEY [azure] Azure Key to use for authentication. Not required if using service principal. See README.md for help finding.
--tenant-id TENANT_ID
[azure] Azure Tenant ID. Only required when using a service principal. See README.md for help finding.
--client-id CLIENT_ID
[azure] Azure client ID (unique ID of service principal). See README.md for help finding.
--client-secret CLIENT_SECRET
[azure] Azure client secret generated for the service principal. See README.md for help generating.
--config CONFIG, -c CONFIG
JSON config file to load. See README.md file for contents.
--print-version, -vv Print the current version and quit.
(venv) $
FAQs
Python SMTP service using aiosmtpd that relays through Azure Email Communication Service
We found that azure-smtp-relay 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.