SMTP ROUTINES ************* ************* ************* FUNCTION _appt_SMS($to) LOCAL $m $m = PROPER(TRIM(GROUP([Forename],1))) IF LEN($m) <= 1 $m = "" ELSE $m = $m|", " END IF $m = $m|"I'm pleased to confirm our appointment on" & FORMAT([appdate],"Ddd mon") & "at" & [apptime] $m = $m & "with" & _safelookup("[agent.Acode],[agent.AForename]",[ACode]) | ". Please call" $m = $m & _safelookup("[agent.Acode],[agent.AMobile]",[ACode]) & "if you have any questions." RETURN _SMSviaSMTP($to,$m) END FUNCTION ' ************************************************************* _SMSviaSMTP FUNCTION _SMSviaSMTP($telno,$smstext) LOCAL #fh $sfile $telno = REPLACESTR($telno," ","") $sfile = "sms.tmp" tools_file("erase",$$localpath|$sfile,"",0) #fh = open_file($$localpath,$sfile,rw_mode) FWRITE #fh FROM "^!TO" FWRITE #fh FROM "sms+"|$telno|"@zyxwvutsrqponm.com" FWRITE #fh FROM "^!FROM" FWRITE #fh FROM "server@abcdefghijklmn.co.uk" FWRITE #fh FROM "^!SUBJECT" FWRITE #fh FROM "Reminder" FWRITE #fh FROM "^!MESSAGE" FWRITE #fh FROM "#Abcdefg#Hijklmn#"|$smstext FCLOSE #fh RETURN _SMTPsend($$localpath|$sfile) END FUNCTION ' *************************************************************** _SMTPsend FUNCTION _SMTPsend($efile) LOCAL #dll IF #testmode _GEMS_display_message("Test mode","Email not sent",4) RETURN 1 END IF DLL LOAD $$homedir|"SWEmail.DLL" #dll IF #dll = 0 _GEMS_display_message("Unable to send email","DLL cannot be loaded",4) RETURN 0 END IF DLL CALL #dll FUNCTION "SMTPSend" STACK "PPPPL"\ DOSPTR($efile) DOSPTR($smtpserver) DOSPTR($smtpuser) DOSPTR($smtppword) #smtpport IF _intAX() <> 1 _GEMS_display_message("Unable to send email","SMTP error during send",4) DLL UNLOAD #dll RETURN 0 END IF DLL UNLOAD #dll RETURN 1 END FUNCTION ' ****************************************************************** _intAX FUNCTION _intAX() ' Returns the value of the AX register, corrected for negative values LOCAL #AXReg #AXreg = GETREG(AX) IF BITAND(#AXreg,0x80000000) 'negative value #AXreg = (#AXreg - 0x80000000) - 0x80000000 END IF RETURN #AXreg END FUNCTION MAPI ROUTINES ************* ************* ************* DLL LOAD $$homedir|"SWEmail.DLL" #dll IF #dll = 0 $msg = "Unable to load email DLL - emailing abandoned" GRAPHICS WINDOW CURSOR 0 _GEMS_WinDialog($msg,$title,48) '! FILE UNLOAD VIEW "nahprnt.vw" EXIT MAIN END IF $profilename = "" $password = "" #emails = 0 #senderr = 0 #noaddr = 0 DATA GOTO RECORD FIRST WHILE RECORD <= RECORDS 'Only send if we have an email address in the [EnqEmail] field IF TRIM([EnqEmail]) <> "" $file = $$homedir|"Email.tmp" $csvfile = $$homedir|STR([key])|".csv" _email_write() DLL CALL #dll FUNCTION "MAPISend" STACK "PPPL"\ DOSPTR($file) DOSPTR($profilename) DOSPTR($password) 0 IF _intAX() <> 1 $msg = "Error sending email for enquiry" & STR([Key]) _GEMS_WinDialog($msg,$title,16) 'X #senderr = #senderr + 1 ELSE #emails = #emails + 1 END IF IF FILE($csvfile) TOOLS FILE ERASE $csvfile END IF IF RECORD <> RECORDS WAIT 2 END IF ELSE #noaddr = #noaddr + 1 END IF LOCK-RECORD [email_stat] = "1" WRITE-RECORD DATA GOTO RECORD NEXT END WHILE DLL UNLOAD #dll FUNCTION _email_write() LOCAL $temp $title IF FILE($file) TOOLS FILE ERASE $file END IF FOPEN $file AS 1 FWRITE 1 FROM "^!TO" FWRITE 1 FROM [EnqEmail] IF TRIM([EnqCCEmail]) <> "" FWRITE 1 FROM "^!CC" FWRITE 1 FROM [EnqCCEmail] END IF FWRITE 1 FROM "^!SUBJECT" $temp = "Enquiry" & STR([Key]) FWRITE 1 FROM $temp FWRITE 1 FROM "^!MESSAGE" FWRITE 1 FROM "Attn:" & [fullname_2] FWRITE 1 FROM "" FWRITE 1 FROM "********************" FWRITE 1 FROM "" FWRITE 1 FROM "You have instructed us to source personal injury victims with potential claims & to conduct investigations for you." FWRITE 1 FROM "" FWRITE 1 FROM "The potential claimant referred to you by this email becomes your immediate responsibility for advice & appropriate action. You indemnify us against any claims from the claimant." FWRITE 1 FROM "" FWRITE 1 FROM "********************" FWRITE 1 FROM "" $temp = "ENQUIRY HANDLED FOR:" IF LEFT([Nature],1)="N" AND [sol_code]="001" $temp = $temp & [sol] & "- Med Neg" ELSE $temp = $temp & [sol] END IF FWRITE 1 FROM $temp FWRITE 1 FROM "" FWRITE 1 FROM [fullname] ... .... FWRITE 1 FROM "********************" FWRITE 1 FROM "******************** End of email" FWRITE 1 FROM "********************" FWRITE 1 FROM "^!ATTACH" FWRITE 1 FROM $csvfile FCLOSE 1 'Now write the csv file IF FILE($csvfile) TOOLS FILE ERASE $csvfile END IF FOPEN $csvfile AS 1 $title = "FirmNo,RefNo,CallDate,CallTime,Status,EmailDate,Title,Forename,Surname" $temp = _csvtext([sol_code])|","|_csvtext(STR([Key]))|"," $temp = $temp|_csvtext(DATE2([crdate]))|","|_csvtext(FORMAT([res_time],"T2"))|"," $temp = $temp|_csvtext([chargestat])|","|_csvtext(TODAY)|"," $temp = $temp|_csvtext([Title])|","|_csvtext([Firstname])|","|_csvtext([sname])|"," FWRITE 1 FROM $title FWRITE 1 FROM $temp FCLOSE 1 END FUNCTION FUNCTION _csvtext($intext) $intext = CHR(34)|REPLACESTR($intext,CHR(34),"~")|CHR(34) RETURN $intext END FUNCTION ' ******************************************************************** _intAX FUNCTION _intAX() ' Returns the value of the AX register, corrected for negative values LOCAL #AXReg #AXreg = GETREG(AX) IF BITAND(#AXreg,0x80000000) 'negative value #AXreg = (#AXreg - 0x80000000) - 0x80000000 END IF RETURN #AXreg END FUNCTION FUNCTION _intAX() ' Returns the value of the AX register, corrected for negative values LOCAL #AXReg #AXreg = GETREG(AX) IF BITAND(#AXreg,0x80000000) 'negative value #AXreg = (#AXreg - 0x80000000) - 0x80000000 END IF RETURN #AXreg END FUNCTION