How to delete file from file directory after sending email?

ChowdaryChowdary Posts: 176Member
edited 2012-05-07 in NAV Three Tier
Hi NAVFamily!

I'm using Bullzip to create invoice PDF and storing in file directory (ex: c:\temp) and sending mails using CU 400. So, all invoices going to "c:\temp"
here is the code:
IF ISCLEAR(BullZipPDF) THEN
CREATE(BullZipPDF);

ReportID := REPORT::"Sales Invoice";
FileDirectory := 'C:\temp';

Window.OPEN('Processing Customer ######################1##');

Object.GET(Object.Type::Report,'',ReportID);

Window.UPDATE(1,"No.");
PDFFileName := "No." + '.pdf';
BullZipPDF.Init;
BullZipPDF.LoadSettings;
RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
BullZipPDF.SetValue('Output',FileDirectory+PDFFileName);
BullZipPDF.SetValue('Showsettings', 'never');
BullZipPDF.SetValue('ShowPDF', 'no');
BullZipPDF.SetValue('ShowProgress', 'no');
BullZipPDF.SetValue('ShowProgressFinished', 'no');
BullZipPDF.SetValue('SuppressErrors', 'yes');
BullZipPDF.SetValue('ConfirmOverwrite', 'no');
BullZipPDF.WriteSettings(TRUE);
Customer2 := "SMTP Customer";
Customer2.SETRECFILTER;
REPORT.RUNMODAL(ReportID,FALSE,FALSE,Customer2);

TimeOut := 0;
WHILE EXISTS(RunOnceFile) AND (TimeOut < 10) DO BEGIN
SLEEP(1000);
TimeOut := TimeOut + 1;
END;

Window.CLOSE;

CLEAR(SMAIL);
SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
SMAIL.Send;

Is there a way to delete file from "c:\temp" after sending email using C/AL code instead of storing?

Thanks

Regards
Chowdary
Pleasure in the job puts perfection in the work

Answers

  • ChowdaryChowdary Posts: 176Member
    Hi Mohana,

    I'm getting this error message
    you cannot use the file C:\temp\1000.pdf because it is already in use.
    code used
    CLEAR(SMAIL);
    SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
    SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
    SMAIL.Send;
    ERASE(FileDirectory+"No."+'.pdf');
    aswel, I tried to use sleep
    code used
    CLEAR(SMAIL);
    SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
    SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
    SMAIL.Send;
    TimeOut1 := 0;
    WHILE EXISTS(FileDirectory+"No."+'.pdf') AND (TimeOut < 10) DO BEGIN
    SLEEP(1000);
    TimeOut1 := TimeOut1 + 1;
    END;
    ERASE(FileDirectory+"No."+'.pdf');

    this code is taking long time and not responding

    am I doing wrong?
    please correct me

    Thanks

    Regards
    Chowdary
    Pleasure in the job puts perfection in the work
  • ChowdaryChowdary Posts: 176Member
    sorry!!

    correction to the code
    WHILE EXISTS(FileDirectory+"No."+'.pdf') AND (TimeOut1 < 10) DO BEGIN

    it's TimeOut1, not TimeOut

    corrected code
    CLEAR(SMAIL);
    SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
    SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
    SMAIL.Send;
    TimeOut1 := 0;
    WHILE EXISTS(FileDirectory+"No."+'.pdf') AND (TimeOut1 < 10) DO BEGIN
    SLEEP(10000);
    TimeOut1 := TimeOut1 + 1;
    END;
    ERASE(FileDirectory+"No."+'.pdf');

    with this code, it's giving the same error, i.e.,
    you cannot use the file C:\temp\1000.pdf because it is already in use.

    depending on the sleep it's taking time to give error message

    Thanks

    Regards
    Chowdary
    Pleasure in the job puts perfection in the work
  • SNielsenSNielsen Posts: 37Member
    This is a known issue with older version of codeunit 400 SMTP Mail, SMTP automation. You can find the updated automation here on my blog: http://gotcal.com/index.php/2010/08/att ... eunit-400/

    Remember to change the code in codeunit 400 to include the port no, and also call the Dispose after the SEnd function.
  • mdPartnerNLmdPartnerNL Posts: 704Member
    SNielsen wrote:
    This is a known issue with older version of codeunit 400 SMTP Mail, SMTP automation. You can find the updated automation here on my blog: http://gotcal.com/index.php/2010/08/att ... eunit-400/

    Remember to change the code in codeunit 400 to include the port no, and also call the Dispose after the SEnd function.

    could you add a .txt of that cu400? when will microsoft release an update?

    the hotfix shows this, thx.
  • ChowdaryChowdary Posts: 176Member
    SNielsen wrote:
    This is a known issue with older version of codeunit 400 SMTP Mail, SMTP automation. You can find the updated automation here on my blog: http://gotcal.com/index.php/2010/08/att ... eunit-400/

    Remember to change the code in codeunit 400 to include the port no, and also call the Dispose after the SEnd function.
    Thank you Nielsen, it's working :thumbsup:
    Did you try with
    ERASE(FileName)
    Thanks Mohana
    Pleasure in the job puts perfection in the work
  • ChowdaryChowdary Posts: 176Member
    Pleasure in the job puts perfection in the work
Sign In or Register to comment.