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...
Answered

SMTP will no longer be available what is the alternate to send an email from AL Code

(0) ShareShare
ReportReport
Posted on by 21,812 Moderator

Hi,

I can see in AL code, while using SMTP Email code unit, getting a warning message "Codeunit 'SMTP Mail' is marked for removal. Reason: Replaced "Email Message" codeunit from "System Application".. Tag: 17.0.".

Does anyone have any idea or any example how to proceed now?

Thanks

  • Suggested answer
    JAngle Profile Picture
    161 on at

    The new version shown in a functional way here: joshanglesea.wordpress.com/.../

    A technical breakdown: dankinsella.blog/.../

  • Nitin Verma Profile Picture
    21,812 Moderator on at

    Thanks josh

  • Patrick Zegels Profile Picture
    5 on at

    Hello Josh,

    We use the SMTP codeunit for cloud printing, and its giving me warnings in VSC that it will be removed.

    However there is no new code available for it.

    can you help me with it ?

    (Code Below)

    codeunit 50000 SendReportByEmailprinter1

    {

       [EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterDocumentPrintReady', '', true, true)]

       local procedure OnDocumentPrintReady(ObjectType: Option "Report","Page"; ObjectId: Integer; ObjectPayload: JsonObject; DocumentStream: InStream; var Success: Boolean);

       var

           SMTPMail: Codeunit "SMTP Mail";

           PrinterNameToken: JsonToken;

           PrinterName: Text;

           ObjectNameToken: JsonToken;

           ObjectName: Text;

           DocumentTypeToken: JsonToken;

           DocumentTypeParts: List of [Text];

           FileExtension: Text;

           MailManagement: Codeunit "Mail Management";

           SendFrom: Text;

           FileName: Text;

           Recipients: List of [Text];

       begin

           begin

               // Step 1: Before doing anything, it is important to check the current Success value

               if Success then

                   exit;

               // Step 2: Make sure code only runs for reports

               if ObjectType = ObjectType::Report then begin

                   // Step 3: Get report object payload information

                   ObjectPayload.Get('printername', PrinterNameToken);

                   PrinterName := PrinterNameToken.AsValue().AsText();

                   if PrinterName = 'Thibo Email to Bizhub C458 Operations' then begin

                       ObjectPayload.Get('objectname', ObjectNameToken);

                       ObjectName := ObjectNameToken.AsValue().AsText();

                       ObjectPayload.Get('documenttype', DocumentTypeToken);

                       // Step 4: Build the email message

                       DocumentTypeParts := DocumentTypeToken.AsValue().AsText().Split('/');

                       FileExtension := DocumentTypeParts.Get(DocumentTypeParts.Count);

                       Recipients.Add('printer1@domain.com');

                       SendFrom := MailManagement.GetSenderEmailAddress();

                       SMTPMail.CreateMessage('Sender', SendFrom, Recipients, 'Email to Printer', 'Please take a look');

                       SMTPMail.AddAttachmentStream(DocumentStream, ObjectName + '.' + FileExtension);

                       // Step 5: Send the email for print

                       SMTPMail.Send();

                       Success := true;

                       exit;

                   end;

               end;

           end;

       end;

    }

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 633 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 419 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 236 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans