AAD B2C custom email verification with Azure Communication Services (ACS) (Azure smtp server)

Amaaz Arshad 135 Reputation points
2025-05-12T21:09:18.2266667+00:00

In AAD B2C custom policies, I want to customize verification email using Azure smtp server i.e. Azure Communication Services (ACS) instead of third party SMTP servers such as sendgrid or mailjet, but i think that the Microsoft provides official documentation of custom email verification with only sendgrid and mailjet. Can anyone help me on this?

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,241 questions
{count} votes

Accepted answer
  1. Suresh Chikkam 2,135 Reputation points Microsoft External Staff Moderator
    2025-05-14T14:05:38.71+00:00

    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 and verificationCode as input and send the email using ACS SMTP.
    • Use a library such as nodemailer (Node.js) or System.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

    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.

    User's image

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.