Unable to send emails using different From addresses in ACS.

Aalap 0 Reputation points
2025-02-18T15:24:16.3133333+00:00

I have created an azure communication service resource and I am able to send an email using the "donotreply" from address but not from any other addresses. We want to be able to send emails using any address in our domain.

This is the following error that I receive when I try to send an email using any address other than donotreply: "Invalid email sender username: 'testuser'. Please use a username from the list of valid usernames configured by your admin.Status: 400 (Bad Request) ErrorCode: InvalidSenderUserName"

I'm using the sample code that was provided by azure with our connection string. I'm just changing the from and to addresses.

using System;
using System.Collections.Generic;
using Azure;
using Azure.Communication.Email;

string connectionString = Environment.GetEnvironmentVariable("COMMUNICATION_SERVICES_CONNECTION_STRING");
var emailClient = new EmailClient(connectionString);


var emailMessage = new EmailMessage(
    senderAddress: "DoNotReply@<from_domain>",
    content: new EmailContent("Test Email")
    {
        PlainText = "Hello world via email.",
        Html = @"
		<html>
			<body>
				<h1>Hello world via email.</h1>
			</body>
		</html>"
    },
    recipients: new EmailRecipients(new List<EmailAddress> { new EmailAddress("<to_email>") }));
    

EmailSendOperation emailSendOperation = emailClient.Send(
    WaitUntil.Completed,
    emailMessage);
Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,013 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Suwarna S Kale 791 Reputation points
    2025-02-18T16:48:12.57+00:00

    Hello Aalap,

    Thank you for posting your question in the Microsoft Q&A forum.

    The issue you're encountering is related to the sender address validation in Azure Communication Services (ACS). By default, ACS only allows sending emails from specific pre-approved sender addresses, such as DoNotReply@<from_domain>. To send emails from other addresses (e.g., addresses in your custom domain), you need to verify and configure those sender addresses in your Azure Communication Services resource.

    To send emails from addresses in your custom domain, you must first verify ownership of the domain. - Useful link https://learn.microsoft.com/en-us/azure/communication-services/concepts/email/email-overview

    1. Navigate to your Azure Communication Services resource in the Azure portal.
    2. Go to Email --> Domains.
    3. Click Add Domain.
    4. Enter your domain name (e.g., yourdomain.com) and click Verify.
    5. Azure will provide you with a TXT record to add to your domain's DNS settings.
    6. Go to your domain registrar or DNS provider and add the TXT record.
    7. Wait for DNS propagation (this can take a few minutes to several hours).

    Once the domain is verified, it will appear in the Domains section with a status of Verified.

    After verifying your domain, you need to configure the sender addresses you want to use. Useful link - https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/add-multiple-senders-mgmt-sdks?pivots=programming-language-csharp

    1. In the Azure portal, go to Email --> Sender Usernames.
    2. Click Add Sender Username.
    3. Enter the email address you want to use (e.g., ******@yourdomain.com).
    4. Click Save.

    If you encounter errors, check the Sender Usernames section in the Azure portal to ensure the address is correctly configured. The link may be useful - https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/send-email?tabs=windows%2Cconnection-string%2Csend-email-and-get-status-async%2Csync-client&pivots=platform-azportal

    If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue.


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.