diff --git a/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al b/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al
index 72a10bc6ad..a676a8b2fe 100644
--- a/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al
+++ b/src/System Application/App/Email/src/Account/EmailAccount.Codeunit.al
@@ -23,12 +23,13 @@ codeunit 8894 "Email Account"
end;
///
- /// Gets all of the email accounts registered in Business Central.
+ /// Gets all of the email accounts which implement the v2 interface registered in Business Central.
///
+ /// Flag, used to determine whether to load the logos for the accounts.
/// Out parameter holding the email accounts.
- procedure GetAllAccounts(var TempEmailAccount: Record "Email Account" temporary)
+ procedure GetAllV2Accounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary)
begin
- EmailAccountImpl.GetAllAccounts(false, TempEmailAccount);
+ EmailAccountImpl.GetAllV2Accounts(LoadLogos, TempEmailAccount);
end;
///
diff --git a/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al b/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al
index 63bc7aa1f9..1888cca01f 100644
--- a/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al
+++ b/src/System Application/App/Email/src/Account/EmailAccountImpl.Codeunit.al
@@ -26,6 +26,16 @@ codeunit 8889 "Email Account Impl."
CannotManageSetupErr: Label 'Your user account does not give you permission to set up email. Please contact your administrator.';
procedure GetAllAccounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary)
+ begin
+ GetAllAccounts(LoadLogos, false, TempEmailAccount);
+ end;
+
+ procedure GetAllV2Accounts(LoadLogos: Boolean; var TempEmailAccount: Record "Email Account" temporary)
+ begin
+ GetAllAccounts(LoadLogos, true, TempEmailAccount);
+ end;
+
+ local procedure GetAllAccounts(LoadLogos: Boolean; LoadV2Only: Boolean; var TempEmailAccount: Record "Email Account" temporary)
var
EmailAccounts: Record "Email Account";
Connector: Enum "Email Connector";
@@ -40,18 +50,19 @@ codeunit 8889 "Email Account Impl."
EmailAccounts.DeleteAll();
IEmailConnector.GetAccounts(EmailAccounts);
- if EmailAccounts.FindSet() then
- repeat
- TempEmailAccount := EmailAccounts;
- TempEmailAccount.Connector := Connector;
+ if (not LoadV2Only) or (LoadV2Only and IEmailConnector is "Email Connector v2") then
+ if EmailAccounts.FindSet() then
+ repeat
+ TempEmailAccount := EmailAccounts;
+ TempEmailAccount.Connector := Connector;
- if LoadLogos then begin
- ImportLogo(TempEmailAccount, Connector);
- ImportLogoBlob(TempEmailAccount, Connector);
- end;
+ if LoadLogos then begin
+ ImportLogo(TempEmailAccount, Connector);
+ ImportLogoBlob(TempEmailAccount, Connector);
+ end;
- if not TempEmailAccount.Insert() then;
- until EmailAccounts.Next() = 0;
+ if not TempEmailAccount.Insert() then;
+ until EmailAccounts.Next() = 0;
end;
// Sort by account name
diff --git a/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al b/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al
index cdb62a58a2..5a7d4f5c25 100644
--- a/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al
+++ b/src/System Application/Test/Email/src/EmailAccountsTest.Codeunit.al
@@ -261,6 +261,49 @@ codeunit 134686 "Email Accounts Test"
Assert.AreEqual(EmailAccountBuffer."Email Address", EmailAccounts."Email Address", 'Wrong account email address');
end;
+ [Test]
+ procedure GetAllV2AccountsTest()
+ var
+ EmailAccountBuffer, EmailAccounts : Record "Email Account";
+ ConnectorMock: Codeunit "Connector Mock";
+ EmailAccount: Codeunit "Email Account";
+ begin
+ // [SCENARIO] GetAllV2Accounts retrieves all the registered accounts that implement the v2 interface
+
+ // [GIVEN] A connector is installed and no account is added
+ ConnectorMock.Initialize();
+
+ PermissionsMock.Set('Email Edit');
+
+ // [WHEN] GetAllAccounts is called
+ EmailAccount.GetAllV2Accounts(EmailAccounts);
+
+ // [THEN] The returned record is empty (there are no registered accounts)
+ Assert.IsTrue(EmailAccounts.IsEmpty(), 'Record should be empty');
+
+ // [GIVEN] An account is added to the connector
+ ConnectorMock.AddAccount(EmailAccountBuffer);
+ // [GIVEN] A v2 account is added to the connector
+ ConnectorMock.AddAccount(EmailAccountBuffer, Enum::"Email Connector"::"Test Email Connector v2");
+
+ // [WHEN] GetAllAccounts is called
+ EmailAccount.GetAllAccounts(EmailAccounts);
+
+ // [THEN] The returned record is not empty and the values are as expected
+ Assert.AreEqual(2, EmailAccounts.Count(), 'Record should not be empty');
+
+ // [WHEN] GetAllV2Accounts is called
+ EmailAccount.GetAllV2Accounts(EmailAccounts);
+
+ // [THEN] The returned record is not empty and the values are as expected
+ Assert.AreEqual(1, EmailAccounts.Count(), 'Record should not be empty');
+ EmailAccounts.FindFirst();
+ Assert.AreEqual(EmailAccountBuffer."Account Id", EmailAccounts."Account Id", 'Wrong account ID');
+ Assert.AreEqual(Enum::"Email Connector"::"Test Email Connector v2", EmailAccounts.Connector, 'Wrong connector');
+ Assert.AreEqual(EmailAccountBuffer.Name, EmailAccounts.Name, 'Wrong account name');
+ Assert.AreEqual(EmailAccountBuffer."Email Address", EmailAccounts."Email Address", 'Wrong account email address');
+ end;
+
[Test]
procedure IsAnyAccountRegisteredTest()
var