Here’s a small snippet on how add automatic CC for all outgoing emails from Business Central via SMTP.
This methods also works when you want to change To or Bcc or even email subject or body.
This code example below checks if user has email setup and if it has then uses that email to add as CC for all outgoing emails.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Mail Management", 'OnBeforeSentViaSMTP', '', false, false)]
local procedure AddCCToEmail(var SMTPMail: Codeunit "SMTP Mail")
var
UserSetup: Record "User Setup";
SendToCcList: List of [Text];
begin
if UserSetup.Get(UserId) then
if UserSetup."E-Mail" <> '' then begin
SMTPMail.GetCC(SendToCcList);
SendToCcList.Add(UserSetup."E-Mail");
SMTPMail.AddCC(SendToCcList);
end;
end;