Error using Email Communication Service in App Service

144 views Asked by At

I'm using Email Communication Services on nestJs API deployed on App Service (Both from Azure) with docker-compose configuration and when I deploy to cloud the email always fails

All my app works, actually the email API also works fine at dev on my local machine, but when I do the deploy I got the same error trying to send email:

code: 400 BadRequest

message: Request body validation error. See property 'senderAddress'

stack-trace: RestError: Request body validation error. See property 'senderAddress' at handleErrorResponse (/node_modules/@azure/core-client/dist/index.js:1321:19) at deserializeResponseBody (/node_modules/@azure/core-client/dist/index.js:1256:45) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Im using currently the provided Azure domain, but I also tried using my own domain. The problem is the same. I changes the domain associated in the Communication Services when I switched domain.

Email domains

Im using connection string to configure the email client, I debugged the senderAddress and the connectionString. Both are correctly provided on local and azure server.

constructor(
    @Inject(emailConfig.KEY)
    emailConf: ConfigType<typeof emailConfig>,
    firestoreService: FirestoreService,
  ) {
    const { appUrl, senderAddress, connectionString } = emailConf;
    this.senderAddress = senderAddress;
    this.emailClient = new EmailClient(connectionString);
    this.appUrl = appUrl;

    this.db = firestoreService.getDatabase();
  }

I also tried this solution: https://learn.microsoft.com/en-us/answers/questions/1183905/azure-communication-service-give-error-the-specifi?page=1&orderby=helpful but didn't work.

Im missing some extra configuration? Should I use some Azure auth specific service? All resources are in the same resource group: Communication Services, Email Communication Services, DNS and App Service

1

There are 1 answers

1
Dizkm8 On

I was searching for information, and actually, the problem was not with the library itself, but with the way that DotEnv and docker-compose deal with the environment variables.

In both .env and docker-compose have this variable:

EMAIL_SENDER_ADDRESS="[email protected]"

Docker-compose do not delete the quotes. I think DotEnv library delete them, or maybe the way .env are, I don't know.

So, the result was having a senderAddress with quotes in my container and the API throws exception because it is not valid for an email.