> For the complete documentation index, see [llms.txt](https://docs.flexbase.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flexbase.in/data-and-providers/providers/e-mail/azure-communication.md).

# Azure Communication

## Description

Azure Communication Services (ACS) Email can be used as the transactional email provider for Azure-hosted applications. Your application code depends on `IFlexEmailProvider`.

## Configuration in DI

Register only the provider.

```csharp
services.AddFlexAzureCommunicationEmailProvider(configuration);
```

## appsettings.json

Configuration is read from `FlexBase:Providers:Email:AzureCommunication`.

```json
{
  "FlexBase": {
    "Providers": {
      "Email": {
        "AzureCommunication": {
          "ConnectionString": "<store-in-secrets>",
          "DefaultFromEmail": "noreply@company.com",
          "DefaultFromName": "Company",
          "MaxRetries": 3,
          "Timeout": "00:00:30",
          "PollingInterval": "00:00:01"
        }
      }
    }
  }
}
```

## Examples (template-based)

This mirrors the generated PostBus handler shape (you do not register the handler manually).

```csharp
using Microsoft.Extensions.Logging;
using Sumeru.Flex;
using System.Threading.Tasks;

namespace {YourApplication}.PostBusHandlers.Email;

public partial class SendAzureCommunicationEmailHandler : ISendAzureCommunicationEmailHandler
{
	protected string EventCondition = string.Empty;

	protected readonly ILogger<SendAzureCommunicationEmailHandler> _logger;
	protected readonly IFlexHost _flexHost;
	protected readonly IFlexEmailProvider _emailProvider;

	protected FlexAppContextBridge? _flexAppContext;

	public SendAzureCommunicationEmailHandler(
		ILogger<SendAzureCommunicationEmailHandler> logger,
		IFlexHost flexHost,
		IFlexEmailProvider emailProvider)
	{
		_logger = logger;
		_flexHost = flexHost;
		_emailProvider = emailProvider;
	}

	public virtual async Task Execute(SendAzureCommunicationEmailCommand cmd, IFlexServiceBusContext serviceBusContext)
	{
		_flexAppContext = cmd.Dto.GetAppContext();  //do not remove this line

		await _emailProvider.SendHtmlAsync(
			to: cmd.Dto.To,
			subject: cmd.Dto.Subject,
			htmlBody: cmd.Dto.Html,
			from: cmd.Dto.From);

		await this.Fire(EventCondition, serviceBusContext);
	}
}
```

## Provider considerations

* Ensure ACS Email domain/sender is verified.
* `PollingInterval` controls how often send status is checked.
