mibuso.com

Microsoft Business Solutions online community
It is currently Tue Nov 25, 2014 2:28 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [Solved] How to delete file from file directory after sending email?
PostPosted: Wed Apr 25, 2012 11:06 am 
Offline

Joined: Mon Jul 26, 2010 12:21 pm
Posts: 141
Country: Mauritius (mu)
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:
Quote:
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


Last edited by Chowdary on Fri Apr 27, 2012 11:16 am, edited 2 times in total.

Top
 Profile E-mail  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Wed Apr 25, 2012 11:09 am 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2014 attendee

Joined: Tue Sep 02, 2008 7:37 am
Posts: 4608
Location: Hyderabad
Country: India (in)
Did you try with
ERASE(FileName)

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav


Top
 Profile  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Wed Apr 25, 2012 1:00 pm 
Offline

Joined: Mon Jul 26, 2010 12:21 pm
Posts: 141
Country: Mauritius (mu)
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
Quote:
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
Quote:
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


Top
 Profile E-mail  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Wed Apr 25, 2012 1:37 pm 
Offline

Joined: Mon Jul 26, 2010 12:21 pm
Posts: 141
Country: Mauritius (mu)
sorry!!

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

it's TimeOut1, not TimeOut

corrected code
Quote:
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


Top
 Profile E-mail  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Wed Apr 25, 2012 7:10 pm 
Offline

Joined: Fri Nov 17, 2000 7:01 am
Posts: 37
Location: California, USA
Country: United States (us)
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.

_________________
--
Soren
http://gotcal.com


Top
 Profile E-mail WWW  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Thu Apr 26, 2012 9:15 am 
Offline

Joined: Tue Jun 21, 2011 12:39 pm
Posts: 580
Country: Netherlands (nl)
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.


Top
 Profile E-mail  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Fri Apr 27, 2012 11:16 am 
Offline

Joined: Mon Jul 26, 2010 12:21 pm
Posts: 141
Country: Mauritius (mu)
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:

Quote:
Did you try with
ERASE(FileName)

Thanks Mohana

_________________
Pleasure in the job puts perfection in the work


Top
 Profile E-mail  
 
 Post subject: Re: How to delete file from file directory after sending ema
PostPosted: Mon May 07, 2012 9:56 am 
Offline

Joined: Mon Jul 26, 2010 12:21 pm
Posts: 141
Country: Mauritius (mu)
http://gotcal.com/index.php/2010/06/smt ... 5-version/

_________________
Pleasure in the job puts perfection in the work


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: