To be able to use send Emails through the Azure Communication Service you need a few ressources that are best created using Infrastructure-as-Code – in this case with Bicep.
Here’s what we need:
- Email Communication Service
- Email Communication Services Domain – either provided by Azure which is good for testing purposes or a custom one for production
- SenderUsername for the domain (e.g. email@example.com)
- Communication Service that is linked to the Domain
To support different environments we also want to use an Azure-managed domain e.g. for dev & test scenarios and a proper custom domain for production.
Only a sucessfully verified Email Communication Service Domain can be linked to the Communication Service. So you might need to run the script, verify the domain when it first fails and then run the script again.
Here’s the full code which can be called directly as a module by just passing the info if we’re in a production environment or not.
Also check out Philipp’s blog post about how to use the Azure Email Communication Service with .NET.