Azure Email Communication Service for Rust (azure-ecs-rs)
Azure Email Communication Service is part of the Azure Communication Services. It provides a REST API to send emails. For more information, see the Azure Communication Services documentation.
This crate provides a Rust client library for the Azure Email Communication Service. It supports the following features: Azure Communication Service - Email - Rest API
Core Features
- Send Email (sync and async)
- Get Email Status
Support Authentication:
- Shared Key
- Service Principle
- Managed Identity
Before running the examples, you need to set the following environment variables:
# For Common
SENDER="xxx
REPLY_EMAIL="xxxx"
REPLY_EMAIL_DISPLAY="xxxx"
# For Shared Key
CONNECTION_STR="xxxxx"
# For SMTP
SMTP_USER="xxxx"
SMTP_PASSWORD="xxxx"
SMTP_SERVER="smtp.azurecomm.net"
# For Service Principle
CLIENT_ID="xx"
CLIENT_SECRET="xxx"
TENANT_ID="xxx"
# Host name
ASC_URL="https://xxxxx.asiapacific.communication.azure.com"
My example code is in the examples
directory. You can run the examples with:
# For simple email
RUST_LOG=debug
# For simple email with async
RUST_LOG=debug
# For email with attachment
RUST_LOG=debug
How to use the library:
-
Shared Key
-
Get from Azure Portal
- CONNECTION_STR
- SENDER
- CONNECTION_STR
let connection_str = get_env_var;
let acs_client_builder = new.connection_string
- Service Principle
let host_name = get_env_var;
let tenant_id = get_env_var;
let client_id = get_env_var;
let client_secret = get_env_var;
let acs_client_builder = new
.host
.service_principal
- Managed Identity
let host_name = get_env_var;
let acs_client_builder = new
.managed_identity
.host
- Send Email
let email_request = new
.sender
.content
.recipients
.user_engagement_tracking_disabled
.build
.expect;
debug!;
let acs_client = acs_client_builder
.build
.expect;
let resp_send_email = acs_client.send_email.await;
- Get Email Status
let resp_send_email = acs_client.send_email.await;
match resp_send_email