Hello Amaaz Arshad,
I understand you are trying to customize the email verification process in Azure AD B2C custom policies using Azure Communication Services (ACS) SMTP, instead of using third-party providers such as SendGrid or Mailjet.
While Azure AD B2C does not support direct SMTP configuration within its policies, Azure Communication Services introduced SMTP support in April 2024. This allows you to implement a workaround by using a custom RESTful API that communicates with ACS SMTP to send verification emails.
To achieve this, you can follow the steps below:
Backend API Implementation :
- Create a REST API (for example, in Node.js, Python, or .NET) hosted on Azure App Service or Azure Functions.
- This API should accept
email
andverificationCode
as input and send the email using ACS SMTP. - Use a library such as
nodemailer
(Node.js) orSystem.Net.Mail
(.NET) to connect to the ACS SMTP endpoint. - Authenticate with the ACS SMTP credentials. You can retrieve these from the Azure portal after creating the ACS Email resource.
Sample SMTP client (Node.js using nodemailer
):
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: '<your-smtp-host>.azurecomm.net',
port: 587,
secure: false,
auth: {
user: '<your-smtp-user>',
pass: '<your-smtp-password>'
}
});
async function sendVerificationEmail(email, code) {
await transporter.sendMail({
from: '<your-smtp-user>',
to: email,
subject: 'Your verification code',
text: `Your verification code is: ${code}`
});
}
In the TrustFrameworkExtensions.xml
, configure a RESTful technical profile to call the API:
<TechnicalProfile Id="SendVerificationEmail">
<DisplayName>Send email via ACS SMTP</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine">
<Metadata>
<Item Key="ServiceUrl">https://your-api.azurewebsites.net/send-email</Item>
<Item Key="SendClaimsIn">Body</Item>
<Item Key="AuthenticationType">None</Item>
<Item Key="AllowInsecureAuthInProduction">false</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="email" />
<InputClaim ClaimTypeReferenceId="verificationCode" />
</InputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</Protocol>
</TechnicalProfile>
<OrchestrationStep Order="2" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="SendVerificationEmail" />
Check the email
and verificationCode
claims are created and populated earlier in your journey.
References
- SMTP support in Azure Communication Services
- Send email via ACS SMTP
- Create RESTful technical profiles in Azure AD B2C
Hope it helps!
Please do not forget to click "Accept the answer” and Yes
wherever the information provided helps you, this can be beneficial to other community members.
If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.