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 :
Microsoft Dynamics NAV (Archived)

SMTP Error - operation timing out

(0) ShareShare
ReportReport
Posted on by 5,136

I created a codeunit that calls the E-Mail Integration codeunit to send email via SMTP.  THis has been working for the longest time.  I am calling this codeunit that sends email via SMTP when user updates the Requested Receipt Date in a Purchase Line table.  All is well except for one order.  For some reason, for this order, it just hangs when I change the Requested Receipt Date ....then eventually errors out with SMTP error - operation time out.  I can't find any problems with the code.  It's really weird.  So I thought I can ask you guys.

For now, I have modified the code so it doesn't run the codeunit that sends email whenever the requested receipt date for this PO # only is modified.  Note that the email recipients if the same for all POs.

Any ideas?

*This post is locked for comments

I have the same question (0)
  • mmv Profile Picture
    11,471 on at

    Hi,

    If the recipients are the same for all orders and if it's working for the other orders, it has to be working for all the Orders with the same recipients.  Could you debug and check where the error is happening?

  • mbr Profile Picture
    5,136 on at

    My thoughts exactly. I spent 4 hrs trying to figure it out. I had debugged and debugged but for some reason for this particular order, the smtp pauses. Well, i found that nav statements are executed asynchronously unless you have conditional statements. But if it passes a condition and you execute 5 statements, nav wont necessarily exec these 5 statements synchronously which may be part of the problem. Thoughts?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    May be there is an repeated loop executing on the validate of date which is causing this timeout.

  • mbr Profile Picture
    5,136 on at

    HI Suresh.  I found the culprit.  He problem is for this PO, the PO Report takes a while to open and save as PDF.  I am using the Report.SaveAsPDF method.  Recently though, we added images into this report so for this particular po, it has a few lines with images so I causes a timeout for the SMTP mail.  Any ideas on how I can circumvent this problem?  I think NAV executes the C/AL code asynchronously so that makes it hard.  I have the Saveas PDF before that actual emailing and so SMTP times out.  I will try and save the file first before even initiating the email.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    As you mentioned, try to execute the code which will save the file and use an if condition if the file exists then execute you mail function. One other thing I don't think NAV executes code asynchronously it executes code synchronously.

  • mbr Profile Picture
    5,136 on at

    Hello All, okay, my workaround didn't work.  Nav executes the statements asynchronously.  How can I work around this?  I.e., I don't even want the Mail init to run until Nav is done saving the report as PDF.  Help!

  • mbr Profile Picture
    5,136 on at

    Hi Suresh.....well for the SMTP, it just runs it without even waiting for the statement (e.g., message) even though the message statement is before it.  I did try to perform saveaspdf first before calling the mail....but it's still timing out.  :(  'still playing with it.

  • mbr Profile Picture
    5,136 on at

    here's my code:

    IF Mode = 'POREQRCTDT' THEN

     BEGIN

           //send PO Report as attachment

           EMailSetup.GET;

           EMailSetup.TESTFIELD("E-Mail Buffer Directory");

           TempFilename := EMailSetup."E-Mail Buffer Directory";

           IF COPYSTR(TempFilename,STRLEN(TempFilename),1) <> '\' THEN

           TempFilename := TempFilename + '\';

           FilePath := TempFilename + 'PO_Report_' + Num + '_Printed_' + FORMAT(TODAY,0,'<Month,2>_<Day,2>_<Year4>') + '.pdf';

           POHeader.SETCURRENTKEY("Document Type","No.");

           POHeader.SETRANGE("Document Type",POHeader."Document Type"::Order);

           POHeader.SETRANGE("No.",Num);

          IF POHeader.FINDSET THEN

            BEGIN

               bDone := REPORT.SAVEASPDF(50000,FilePath,POHeader);    //save as pdf

            END;

     END;

    //so in essence it should wait until saveaspdf is done

    //prepare recipients

    CASE Mode OF

     'POREQRCTDT':

        BEGIN

    MailInt.InitializeMail(EmailSubject);   //but it seems to run this

    MailInt.LineFeedChar := LF;

            CLEAR(UserSetup);

            UserSetup.SETCURRENTKEY(AutoEmailPOReqRctDt,"E-Mail Recipient Address");

            UserSetup.SETRANGE(AutoEmailPOReqRctDt,TRUE);

            IF UserSetup.FINDSET THEN

               REPEAT

                 MailInt.AddReceiverTo(UserSetup."E-Mail Recipient Address");

                 bEmail := TRUE;

               UNTIL UserSetup.NEXT =0;

                    IF STRLEN(FilePath) > 0 THEN

               MailInt.AddAttachment(FilePath);      //for attachment

         END;

    //when ran, it pauses for a while as the saveaspdf is taking a while...well actually the report is loading for a while due to the images.....then I eventually get an SMTP timeout problem.

  • Verified answer
    mbr Profile Picture
    5,136 on at

    OKAY! I figured it out! Whew! The problem was with the SMTP Mail filesize attachment limitation.  Since this particular PO report was actually > 2.5 MB in size, the SMTP times out because it's too big.  Yaikks! I didn't think about that.  Anyway, I had developed a workaround whereby I check the PDF file size before attempting to attach.  If it is > 2.5, then don't attach and write a note in the body of the email.  Thank you all for all your insights.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    In your statement the REPORT.SAVEASPDF executes on the backend, so it executes the next statement right away, what you can do is add a while loop before your CASE Statement and keep on repeat until you find the file basically or you SLEEP function after REPORT.SAVEASPDF.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans