Ir al contenido principal

Sage X3 How to send an e-mail


Sometimes X3 developers needs to send e-mail messages at the end of a batch procedure or from a custom form.
To facilitate these tasks I’ve written a simple Subprog that can be use where you need.
That’s the Subprog
For Sage X3 version 1.4.x
  1. Subprog SEND_MAIL(PTO,PCC,PSUBJECT,PTEXT,PJOIFIC)
  2. Value Char PSUBJECT
  3. Value Char PTEXT
  4. Value Char PJOIFIC
  5. Local Integer PNUMLIN : PNUMLIN = dim(XMSG)
  6. Local Integer XTOTDIM : XTOTDIM = 3+PNUMLIN
  7. Local Integer XCONTA
  8. If PCC <> "" Then
  9. XTOTDIM += 1
  10. Endif
  11. Local Char ENVOI(250)(1..XTOTDIM)
  12. Local Integer XN : XN = 0
  13. XN += 1
  14. ENVOI(XN) = "__TO="+chr$(1)+PTO
  15. If PCC <> "" Then
  16. XN += 1
  17. ENVOI(XN) = "__CC="+chr$(1)+PCC
  18. Endif
  19. XN += 1
  20. ENVOI(XN) = "__SUJET="+chr$(1)+PSUBJECT
  21. For XCONTA = 0 To PNUMLIN - 1
  22. ENVOI(XCONTA+XN+1) = "__NOTE="+chr$(XCONTA+1)+PTEXT(XCONTA)
  23. If XCONTA < PNUMLIN - 1 Then
  24. ENVOI(XCONTA+XN+1)+=chr$(10)
  25. Endif
  26. Next
  27. XN = XN + PNUMLIN
  28. If PJOIFIC <> "" Then
  29. XN += 1
  30. ENVOI(XN) = "__JOINT="+chr$(1)+PJOIFIC
  31. Endif
  32. Call SEND_MESS(2,ENVOI(1..XN)) From SUBAMSC
  33. End

For Sage X3 version 5, 6 and 9
  1. Subprog SEND_MAIL(PTO,PCC,PSUBJECT,PTEXT,PJOINFIC)
  2. Value Char PTO
  3. Value Char PCC
  4. Value Char PSUBJECT
  5. Value Char PTEXT
  6. Value Char PJOINFIC
  7. #YTYPMES: 1 = use the global parameter GTYPMES, 2 = sent by server, 3 = sent by client
  8. Local Integer YTYPMES : YTYPMES = 1
  9. #2 = Retrun receipt
  10. Local Integer YREQREC : YREQREC = 2
  11. #Importance 1=Low 3=High
  12. Local Integer YREQIMP : YREQIMP = 2
  13. Local Char YUSER(20) : YUSER = GUSER
  14. Local Char YMAIL(250) : YMAIL = ""
  15. Local Char YOBJJOI(250) : YOBJJOI = ""
  16. Local Char YCLEOBJ(250) : YCLEOBJ = ""
  17. Local Char YCHRONO(250) : YCHRONO = ""
  18. # 0 -> No detailed trace. >0 -> Write detailed trace
  19. Local Integer YERD
  20. YERD = val(func AFNC.PARAMDOS(nomap,"TRAMEL"))-1 #Read the dossier's param
  21. Local Char YUSR_EMAIL(250)(0..999)
  22. Local Integer YUSR_ENVOI(0..999)
  23. Local Integer YUSR_SUIVI(0..999)
  24. Local Integer YUSR_NB
  25. Local Clbfile YTEXCLB
  26. Local Char YTEXOBJ(250) : YTEXOBJ = PSUBJECT
  27. Local Char YPCEJOI(250)(1..99)
  28. Local Integer YNBJOI
  29. Local Char YTYPJOI(250) : YTYPJOI(0) = ""
  30. Local Integer YCATJOI : YCATJOI = 0
  31. Local Char YCONTXT(250) : YCONTXT(0) = ""
  32. #
  33. #Recipients
  34. #
  35. YUSR_NB = 0
  36. Local Integer I
  37. For I = 0 To dim(PTO) - 1
  38. If vireblc(PTO(I),2) <> "" Then
  39. YUSR_EMAIL(YUSR_NB) = vireblc(PTO(I),2)
  40. YUSR_ENVOI(YUSR_NB) = 2
  41. YUSR_NB += 1
  42. Endif
  43. Next
  44. For I = 0 To dim(PCC) - 1
  45. If vireblc(PCC(I), 2) <> "" Then
  46. YUSR_EMAIL(YUSR_NB) = vireblc(PCC(I), 2)
  47. YUSR_ENVOI(YUSR_NB) = 3
  48. YUSR_NB += 1
  49. Endif
  50. Next
  51. #
  52. # Attachment
  53. #
  54. YNBJOI = 0
  55. For I = 0 To dim(PJOINFIC) - 1
  56. If vireblc(PJOINFIC(I),2) <> "" Then
  57. YNBJOI += 1
  58. YPCEJOI(YNBJOI) = vireblc(PJOINFIC(I),2)
  59. Endif
  60. Next
  61. Setlob YTEXCLB With PTEXT
  62. Call ENVOI_MAIL(YTYPMES,YREQREC,YREQIMP,YUSER,YMAIL,YOBJJOI,YCLEOBJ
  63. & ,YCHRONO,YERD,YUSR_EMAIL,YUSR_ENVOI,YUSR_SUIVI,YUSR_NB
  64. & ,YTEXCLB,YTEXOBJ
  65. & ,YPCEJOI,YNBJOI,YTYPJOI,YCATJOI,YCONTXT) From AWRKMEL
  66. End
Here an example of how to call the Subprog
  1. Local Char XMSG(250)(8)
  2. Local Char XSUJET(250)
  3. Local Integer XXCONTA : XXCONTA = 0
  4. XXCONTA += 1: XMSG(XXCONTA) = "Test email body, row1" + num$(XXCONTA)
  5. XXCONTA += 1: XMSG(XXCONTA) = "row 2 " + num$(XXCONTA)
  6. XSUJET = "E-mail subject"
  7. Call SEND_MAIL("xxx.xxx@xxxxx.xxx","",XSUJET,XMSG,"")
Here how to send the current trace
  1. Local Char XMSG(250)(6)
  2. Local Char XSUJET(250)
  3. Local Integer XXCONTA : XXCONTA = 0
  4. XXCONTA += 1: XMSG(XXCONTA) = "Test email body, row1" + num$(XXCONTA)
  5. XXCONTA += 1: XMSG(XXCONTA) = "row 2 " + num$(XXCONTA)
  6. XSUJET = "E-mail subject"
  7. If GTRACE <> "" Then
  8. XFTRACE = func F_FIC_TRACE(GTRACE)
  9. XMSG(6) = "----------"
  10. XMSG(7) = XFTRACE
  11. Endif
  12. Call SEND_MAIL("xxx.xxxxx@xxxxx.xx","xxxx_cc@xxxxx.xx",XSUJET,XMSG,XFTRACE)
The F_FIC_TRACE it’s a function tha return the full path of the trace
  1. Funprog F_FIC_TRACE(XGTRACE)
  2. Value Char XGTRACE
  3. Local Char WNAME(250)
  4. If left$(XGTRACE,2)="#@" & (GBROWS | GSERVEUR)
  5. WNAME = ""
  6. Elsif max(instr(1,XGTRACE,"/"),instr(1,XGTRACE,"\"),instr(1,XGTRACE,"@"))
  7. WNAME = XGTRACE
  8. Else
  9. WNAME = filpath("TRA",XGTRACE,"tra")
  10. Endif
  11. If filinfo(WNAME,0)=0
  12. WNAME = ""
  13. Endif
  14. End WNAME

Entradas populares de este blog

SAGE X3 SILENT IMPORT (IMPORTSIL) WITH ERROR CATCHING

FUENTE ORIGINAL: https://pluginx3.com/en/blog/post/sage-x3-silent-import-importsil-with-error-catching.html You already know how to manually generate a CSV file in order to import it threw a template in Sage X3. But If you wonder how to catch detailed errors after a silent import here is the solution. Sometimes you need to catch the incoming errors in order to alert the end-user regarding an issue. Closed period, wrong date etc …. Unfortunalty the standard Sage X3 silent import function doesn’t natively show the detailed errors during the import process. Call IMPORTSIL([M:IMP2]MODIMP,[M:IMP2]NOMIMP) From GIMPOBJ And the standard function ERR_IMPORT will only show the overall status of the importation and not the detailed errors. IMPORTSIL function is pushing all the log data into a tracefile in order to avoid any popup on end-user screen. So you have a log file available in order to search for errors in it. Sage X3 runtime is using the same principals standards as any shell for log...

Valores de fstat

Fstat fstat  is a numeric status that is returned upon execution of a database operation, a sequential file operation, or a lock instruction. Syntax fstat Examples # MYTABLE is a table with a key called KEY1, that has a unique component called KEYVAL # Create a record in the table MYTABLE with they key value 1 if it doesn't exist Local File MYTABLE [MYT] Read [MYT]KEY1=1 If fstat [MYT]KEYVAL=1 : Write [MYT] If fstat MSG="The key was created in the mean time" Else MSG="Key created" Endif Else MSG="Key already exists" Endif Details fstat  is always set to '0' if the operation is successfully completed, and has a non-null value if there is an error: In a sequential read ( Getseq  and  Rdseq ),  fstat  is set to '1' at the end of the file. On  Lock ,  fstat  is set to '1' if the lock could not be performed. For a database operation ( Read ,  Look ,  Readlock ,  For ,  Write ,  ...

Sage X3 Create a new CLOB Text

Here how to create a CLOB text Funprog F_CRELOB ( YABRFIC , YTEXTE ) Value Char YABRFIC Value Char YTEXTE Local Char XXRTFTXT ( 250 ) ( 3 ) XXRTFTXT ( 0 ) = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 MS Sans Serif;}}\viewkind4\uc1\pard\f0\fs17 " XXRTFTXT ( 1 ) = YTEXTE XXRTFTXT ( 2 ) = "\par}" Local Char X_RET Local Integer XXOK Local Char XCHAMPLIEN : XCHAMPLIEN = "YYYY" Global Char YYYY : YYYY = YABRFIC Local Clbfile WWCLOB Local Mask ACLOB [ M :ACL ] Setlob WWCLOB With XXRTFTXT [ M :ACL ] CLOB = WWCLOB Call CRE_CLOB_ACL ( XCHAMPLIEN , XXOK ) From TRTX3TEX Close Local Mask [ M :ACL ] X_RET = YYYY Kill YYYY End X_RET