Email as attachment using Report

hi experts !!!

i have face issue while sending email as Attachment in nav 2013 .

i have written following code .

Sales Invoice Header - OnPreDataItem()

Sales Invoice Header - OnAfterGetRecord()

SMTPStup.GET;

CLEAR(SmtpMail);

ToFile := ‘invoice’;
FileName := TEMPORARYPATH + ToFile;
REPORT.SAVEASPDF(60020, FileName,“Sales Invoice Header”);
ToFile := DownloadToClientFileName(FileName, ToFile);

SmtpMail.CreateMessage(‘Sachin Chaudhari’,‘support@sergas.com’,‘sachin.chaudhari@robo-soft.net’,‘Invoice Generated’,’’,FALSE);
SmtpMail.AddAttachment(ToFile);
SmtpMail.AppendBody(‘Dear Sir/mam’);
SmtpMail.AppendBody(’

’);
SmtpMail.AppendBody(‘Please Find The Attachments’);
SmtpMail.AppendBody(’

’);
SmtpMail.AppendBody(‘Regards’);
SmtpMail.AppendBody(’

’);
SmtpMail.AppendBody(‘Sachin’);

SmtpMail.Send;

Sales Invoice Header - OnPostDataItem()

DownloadToClientFileName(FileDownLoad : Text;ToFile : Text) : Text
IF NOT ISSERVICETIER THEN
EXIT;

FileVar.OPEN(FileDownLoad);
FileVar.CREATEINSTREAM(IStream);
DOWNLOADFROMSTREAM(IStream,’’,’’,’’,MagicPath);
MagicPath1:=MagicPath;
EXIT(MagicPath1);
FileVar.CLOSE;

but when i run report its gives me error

Attachment "path name"does not exists or can not be accessed from program…

please help me…

Can you show the full error message that you are getting?

Please debug to see TEMPORARYPATH variable has value.