This is a very simple Azure Function example that allows you to send emails using an SMTP connection. It written using .NET 6
and uses the Mailkit
nuget package.
- Make sure the .NET 6 SDK has been installed
- Make sure Azure Functions Core Tools has been installed (
npm i -g azure-functions-core-tools@4 --unsafe-perm true
)
Configure the following SMTP_
variables in your local.settings.json
file (with your own SMTP credentials):
{
// ...
"Values": {
// ...
"SMTP_SERVER": "your_smtp_server",
"SMTP_PORT": "587",
"SMTP_SSL": "true",
"SMTP_FROM": "your_name",
"SMTP_USERNAME": "your_username",
"SMTP_PASSWORD": "your_password"
}
}
Then, run:
func start
It should give you the Azure Function url that you can call and probably looks something like this:
send_email: [POST] http://localhost:7071/api/send_email
Using your HTTP client of choice, post the following json data to the endpoint:
Note: you should be able to use HTML(!)
// POST: http://localhost:7071/api/send_email
{
"To": "[email protected]",
"Subject": "Hello from Azure Functions!",
"Body": "<h1>An awesome email has arrived</h1> \n\n <p>This is a test email sent from an Azure Function using SMTP.</p>",
"Important": true
}