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

Notifications

Announcements

No record found.

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,708 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

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

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

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

  • Nitin Verma Profile Picture
    21,708 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans