Skip to content

Comments

Bug6451 email without top domain#6781

Open
Dan-Karlsson wants to merge 2 commits intomicrosoft:mainfrom
Dan-Karlsson:Bug6451-Email-Without-Top-Domain
Open

Bug6451 email without top domain#6781
Dan-Karlsson wants to merge 2 commits intomicrosoft:mainfrom
Dan-Karlsson:Bug6451-Email-Without-Top-Domain

Conversation

@Dan-Karlsson
Copy link

@Dan-Karlsson Dan-Karlsson commented Feb 23, 2026

Summary

Validate email addresses to ensure they contain a top domain and that the top domain is at least 2 characters long

Work Item(s)

Fixes #6451

@Dan-Karlsson Dan-Karlsson requested a review from a team as a code owner February 23, 2026 19:34
@github-actions github-actions bot added AL: System Application From Fork Pull request is coming from a fork labels Feb 23, 2026
Copy link

@duichwer duichwer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests with error assertions?

@Dan-Karlsson
Copy link
Author

Could you add some tests with error assertions?

I can't find any tests of those functions, so I'm not sure where to put them. And I'm also not sure how to write them to not risk failure with .Net-calls in different environments and similar.

@duichwer
Copy link

Could you add some tests with error assertions?

I can't find any tests of those functions, so I'm not sure where to put them. And I'm also not sure how to write them to not risk failure with .Net-calls in different environments and similar.

@Dan-Karlsson I think you're correct.
I couldn't find any tests for the mail validation in the system application tests either.
That doesn't mean that we shouldn't have there some tests.

There are some tests in the Base Application for the procedure CheckValidEmailAddress of codeunit "Mail Management"
https://github.com/microsoft/BusinessCentralApps/blob/main/App/Layers/W1/Tests/Integration-Internal/MailManagementTest.Codeunit.al
The procedure CheckValidEmailAddress internall calls the procedure of the email account codeunit

    [TryFunction]
    procedure CheckValidEmailAddress(EmailAddress: Text)
    var
        EmailAccount: Codeunit "Email Account";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        OnBeforeCheckValidEmailAddr(EmailAddress, IsHandled);
        if IsHandled then
            exit;

        EmailAddress := DelChr(EmailAddress, '<>');

        // Check that only one address is validated.
        if EmailAddress.Split('@').Count() <> 2 then
            Error(InvalidEmailAddressErr, EmailAddress);

        if not EmailAccount.ValidateEmailAddress(EmailAddress) then
            Error(InvalidEmailAddressErr, EmailAddress);
    end;

Therefore I would suggest to some tests to https://github.com/microsoft/BCApps/blob/main/src/System%20Application/Test/Email/src/EmailAccountsTest.Codeunit.al.

@Dan-Karlsson
Copy link
Author

@Dan-Karlsson I think you're correct. I couldn't find any tests for the mail validation in the system application tests either. That doesn't mean that we shouldn't have there some tests.

There are some tests in the Base Application for the procedure CheckValidEmailAddress of codeunit "Mail Management" https://github.com/microsoft/BusinessCentralApps/blob/main/App/Layers/W1/Tests/Integration-Internal/MailManagementTest.Codeunit.al The procedure CheckValidEmailAddress internall calls the procedure of the email account codeunit

Therefore I would suggest to some tests to https://github.com/microsoft/BCApps/blob/main/src/System%20Application/Test/Email/src/EmailAccountsTest.Codeunit.al.

Thank you! I didn't think to check in Base Application.

But I think the tests should be in Base Application, with added tests in the procedure TestInvalidEmailAddress. It's bad design to test some cases there and some other cases in a completely different part of the code.

    procedure TestInvalidEmailAddress()
    var
        MailManagement: Codeunit "Mail Management";
    begin
        asserterror MailManagement.CheckValidEmailAddress('@a');
        asserterror MailManagement.CheckValidEmailAddress('b@');
        asserterror MailManagement.CheckValidEmailAddress('ab)@c.d');
        asserterror MailManagement.CheckValidEmailAddress('a@@b');
    end;

But I don't know how to add it there (without creating a new bug report in Base and a separate pull request for the tests, that won't work until this is approved).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: System Application From Fork Pull request is coming from a fork

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Email Address Without Top Domain is Validated

2 participants