An Azure function with a HTTP trigger for sending email to an SMTP endpoint, to be used with concurrency for load testing.
POST
{
"endpoint": "smtp.some-endpoint.com",
"port": 25,
"timeout": 3.5,
"tenant_id": "f45af6e4-4206-4e5b-8675-d4852a158dbf",
"recipient": "[email protected]",
"sender": "[email protected]"
}
All fields are required, with the exception of:
port
, which defaults to25
if not specified.timeout
, which defaults tonull
if not specified.
200
: if email successfully sent to endpoint.400
: if request body not present or malformed.500
: if there was a general error in the function.502
: if there was some error sending the email to the SMTP endpoint.
- Serverless framework
- Python 3.8
- Pipenv
- Clone this repo.
- Set up your pipenv by running
pipenv sync --dev
. - Launch the function with
pipenv run serverless offline --region uksouth
. - Edit the code and test. I use HTTPie for making requests.
- In order to have something to test with, you can run a postfix blackhole mail server on port 25 using Docker, with:
docker run --name blackhole -d -p 25:25 simap/smtpblackhole
. - Now, using HTTPie to make a request to the locally running function:
http post http://localhost:7071/api/send endpoint=localhost port=25 tenant_id=test [email protected] [email protected]
. - You should get back something like this:
HTTP/1.1 200 OK Content-Type: text/plain; charset=utf-8 Date: Tue, 30 Jun 2020 13:51:51 GMT Server: Kestrel Transfer-Encoding: chunked Successfully sent to 'localhost:25'