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.