web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

AzureAD App Send Email

(0) ShareShare
ReportReport
Posted on by

Hello,

We're developing an app that is accessing the BC API using an AzureAD registered app. We're successfully sending POST and PATCH requests to Business Central, but we're working on exception handling and trying to - as a first step - get the app to trigger an email send.

We've written a Codeunit that is triggered when our app changes a field in one of the tables. The Codeunit runs successfully, reads the data from our staging table and moves it into the final data table. We've added a catch on the final Insert() operation so that if it fails it runs our EmailNotify procedure, which is defined in the same codeunit.

We've debugged this and it runs. It's not sending the email, though as it's trying the send as our app. 

pastedimage1652869383820v1.png

What I want to know is do we need to assign the app permissions at the AzureAD side of things, and if that's the case what permissions are required? If it's an issue at the Business Central side of things, what permissions do we need to assign our AzureAD application to allow it to send the email?

I'm absolutely certain that other devs will have apps that do this, and I've got the email sending working in one of our other extensions. The only difference is this is coming from an AzureAD registered app, even though the app itself isn't doing the sending, it's just triggering the codeunit.

Any help would be appreciated. We're stumbling around in the dark on this.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    I am not sure that i understand exactly what you are trying to do without having access to your code.

    But if you want the app to trigger e-mails you must use an e-mail account that is not a personal account but is a generic a-mail account defined in Business Central.

    When i implement BC i have the personal e-mail accounts defined but also a generic default address like no-reply@mycompany.com

    So your app would need to use that e-mail account to send e-mail.

  • AkaiRingo3559 Profile Picture
    on at

    local procedure AlertNotify(header: Text[50]; message: Text[200])
        var
            TxtRecipientList: List of [Text];
            EmailObj: Codeunit "Email";
            EmailMsg: Codeunit "Email Message";
        begin
            //DEBUG:
            TxtRecipientList.Add('testemailaddress@ourdomain.co.uk');
    
            EmailMsg.Create(
                TxtRecipientList,
                header,
                message,
                false
            );
            EmailObj.Send(EmailMsg, Enum::"Email Scenario"::Default);
            GetSender();
        end;

    This is our AlertNotify procedure. It was lifted from our other extension which is triggered by a job queue entry failure. It all works fine, and when a job fails we get an email.

    All we're trying to do is run this procedure as part of our codeunit, which is triggered by our app changing a field - the OnModify trigger detects a change and then executes our codeunit. As I say, the codeunit runs, it goes into the AlertNotify procedure and runs all the code - it's just not able to send the email and gives the above mentioned reason.

    We already have an account set up as the sending account, and this is all working fine in the other extension. The issue is the listed sender in this case is our AzureAD app, and this seems to be where the problem lies.

    pastedimage1652871336448v1.png

    The codeunit is being triggered by a change made by our automated integration service, but it's obviously passing through the OAuth credentials that it receives before POSTing the data. Interestingly, when I click on the failed message and select Show Source, it pops up a user card for one of our users.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 545 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 354 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 228 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans