I have created a .html file from a Progress program which contains a table of rows and columns.
I would like to add the contents of the HTML file to an email body that I am sending with the "febooti" email utility on Windows.
How can I send this HTML file from my Progress program using "febooti"?
The febooti.com website says that the tool supports HTML in the body of the email:
https://www.febooti.com/products/command-line-email/commands/htmlfile/
There are a lot of options but a simple 4gl test example might look something like this:
define variable smtpServer as character no-undo.
define variable emailFrom as character no-undo.
define variable emailTo as character no-undo.
define variable emailSubject as character no-undo.
define variable altText as character no-undo.
define variable htmlFileName as character no-undo.
define variable htmlContent as character no-undo.
assign
smtpServer = "smtp.server.com"
emailFrom = "varun#email.com"
emailTo = "someone#email.com"
emailSubject = "Test email!"
altText = "Sorry, your email app cannot display HTML"
htmlFileName = "test.html"
.
/* this is obviously just an example, according to your question you
* have already created the HTML and don't actually need to do this
*/
htmlContent = "<table> <tr><td>abc</td></tr> <tr><td>...</td></tr> <tr><td>xyz</td></tr> </table>".
output to value( htmlFileName ).
put unformatted htmlFile skip.
output close.
/* end of stub html file creation - use your real code */
/* this shells out and sends the email using whatever
* is in htmlFileName as the content
*/
os-command value( substitute( "febootimail -SERVER &1 -FROM &2 -TO &3 -SUBJECT &4 -HTMLFILE &5 -TEXT &6", smtpServer, emailFrom, emailTo, emailSubject, htmlFileName, altText )).
Related
In my program I am outputting a .csv file which exceeds 1000000 lines. Currently after the file is exported, I am splitting the file from linux using the below commands. However, I would like to know if we can split the files using a progress code. If so, could someone plese let me know on how to do it.
Below is the linux command I use manually.
ls -l xa*
split -1000000 filename.csv
mv xaa filename-01.csv
mv xab filename-02.csv
Without any code to work with I invented some code outputting to different files. You will have to work with OUTPUT TO and set new filenames.
This example will output 1050 lines split in files of 100 lines each.
DEFINE VARIABLE iLinesToOutput AS INTEGER NO-UNDO INIT 1050.
DEFINE VARIABLE iSplitAt AS INTEGER NO-UNDO INIT 100.
DEFINE VARIABLE iLine AS INTEGER NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE iFile AS INTEGER NO-UNDO.
DEFINE VARIABLE iOpen AS INTEGER NO-UNDO.
DEFINE STREAM str.
DO iLine = 1 TO iLinesToOutput:
// Open a new stream/file
IF (iLine - 1 ) MOD iSplitAt = 0 THEN DO:
iFile = iFile + 1.
cFile = "c:\temp\file-" + STRING(iFile, "999") + ".txt".
OUTPUT STREAM str TO VALUE(cFile).
EXPORT STREAM str DELIMITER "," "Customer ID" "Order Number" "Contact" "Count"
END.
// Output some data
PUT STREAM str UNFORMATTED "Line " iLine SKIP.
// Close the stream/file
IF iLine MOD iSplitAt = 0 THEN DO:
OUTPUT STREAM str CLOSE.
END.
END.
/* Close last file if not exactly right number of lines */
/* This could also be checked but close twice doesn't really matter */
OUTPUT STREAM str CLOSE.
I have used the below .NET ABL code to print the pdf using the default printer option. Now I want to set those Printer and Page settings. I know they are in System.Drawing.Printing setting, but anyone knows how to integrate this with the ProcessStartInfo to print it with those parameter settings.
USING System.*.
USING System.Collections.Generic.*.
USING System.Diagnostics.*.
USING System.IO.*.
USING System.Linq.*.
USING System.Text.*.
USING System.Threading.Tasks.*.
USING System.Drawing.*.
DEFINE VARIABLE proc AS System.Diagnostics.Process NO-UNDO.
DEFINE VARIABLE startInfo AS System.Diagnostics.ProcessStartInfo NO-UNDO.
DEFINE VARIABLE printerSettings AS System.Drawing.Printing.PrinterSettings NO-UNDO.
DEFINE VARIABLE pageSettings AS System.Drawing.Printing.PageSettings NO-UNDO.
DEFINE VARIABLE sFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE sPrinter AS CHARACTER NO-UNDO.
DEFINE VARIABLE sArgs AS CHARACTER NO-UNDO.
/* HOW To Handle Printer and Page Settings here?
ASSIGN
printerSettings = NEW System.Drawing.Printing.PrinterSettings()
printerSettings:PrinterName = "Microsoft Print to PDF (redirected 4)"
printerSettings:Copies = 01.
ASSIGN
pageSettings = new System.Drawing.Printing.PageSettings(printerSettings).
*/
ASSIGN
startInfo = new System.Diagnostics.ProcessStartInfo()
sFileName = "C:\temp\file.pdf"
startInfo:FileName = sFileName
sPrinter = "Microsoft Print to PDF (redirected 4)"
startInfo:Verb = "print"
startInfo:Arguments=sPrinter.
ASSIGN
startInfo:WindowStyle = System.Diagnostics.ProcessWindowStyle:HIDDEN
startInfo:CreateNoWindow = TRUE
proc = System.Diagnostics.Process:Start(startInfo).
proc:WaitForExit(15000).
IF NOT proc:HasExited THEN DO:
proc:Kill().
proc:Dispose().
END.
Any help will be highly appreciable.
Regards
DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.
ASSIGN
cPath = "R:\Downloads\progress\".
cExt = ".Txt".
cMessageDateTime = "123456789".
OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).
cExportData = "Data1" + CHR(10) + "Data2" + CHR(10) + "Data3" + CHR(10) + "END.".
MESSAGE cExportData.
OUTPUT TO CLOSE.
So when I see exported text file using notepad++ i could see first 3 for Data1,Data2,Data3 but 4th line is created with empty.How do I stop creating empty line.
MESSAGE is not usually what you want to use for output to a file, it has many extra behaviors specific to interacting with users in the context of providing error messages etc. PUT is generally more appropriate for writing files. Embedding CHR(10) is also not a good idea -- that is a very OS specific line terminator. CHR(10) is a Unix style newline but you are clearly running on Windows (which uses CHR(10) + CHR(13).
I might re-write your code as follows:
DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.
/* the "." that you had at the ends of the ASSIGN sub statements
* is turning it into 3 distinct statements, not one as your
* indentation shows
*/
ASSIGN
cPath = "R:\Downloads\progress\"
cExt = ".Txt"
cMessageDateTime = "123456789"
. /* end the ASSIGN statement */
/* if you are using MTIME because you imagine it will make your
* filename unique then you are mistaken, on a multi-user or
* networked system it is trivial for 2 processes to create files
* at the very same MTIME
*/
OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).
/* usually some kind of looping structure would output each line
* building the whole output by concatenating into a string will
* eventually exhaust memory.
*/
put unformatted "Data1" skip "Data2" skip "Data3" skip "End." skip.
/* the final SKIP might not be needed - it is unclear to me
* if that is a problem for your client
*/
/* as originally written this creates
* an empty file called "CLOSE"
*/
OUTPUT /*** TO ***/ CLOSE.
I have written a program for export some text files to a specific directory. So i preferred using MTIME is the best way to have a unique name but this will be a problem when multiple process exporting same file name using MTIME.
Could you please tell me the best way to have a unique file name? Let me share some sample.
DEFINE INPUT PARAMETER ipData1 AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER ipData2 AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER ipData3 AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.
ASSIGN
cPath = "R:\Downloads\progress\"
cExt = ".Txt"
cMessageDateTime = "123456789".
OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).
put unformatted ipData1 skip ipData2 skip ipData3 skip "End."
OUTPUT CLOSE.
You have several options:
Use the program that Progress has supplied: adecomm/_tmpfile.p
define variable fname as character no-undo format "x(30)".
run adecomm/_tmpfile.p ( "xxx", ".tmp", output fname ).
display fname.
Use a GUID:
define variable fname as character no-undo format "x(30)".
fname = substitute( "&1&3&2", "xxx", ".tmp", GUID( GENERATE-UUID )).
display fname.
Ask Windows to do it (if you are always running on Windows):
define variable fname as character no-undo format "x(30)".
fname = System.IO.Path:GetTempFileName().
display fname.
Trial and error:
define variable fname as character no-undo.
do while true:
fname = substitute( "&1&3&2", "xxx", ".tmp", string( random( 1, 1000 ), "9999" )).
file-info:filename = fname.
if file-info:full-pathname = ? then leave. /* if the file does NOT exist it is ok to use this name */
end.
display fname.
You'll probably also need to pass in a token or an identifier of some sort to make this truly unique. Maybe username, or the machine's up, something like that. Then my advice would be concatenating that with
REPLACE (STRING(TODAY),'/','') + STRING(MTIME).
Edit: even though OP has flagged my answer as correct, it's not. Check Tom's answer to this for better options.
i have used this before.
("Filename" + STRING(TODAY,"999999") + ".csv").
I am playing around with adding some custom tools to my PSDOE. I have added a new toolbar entry to experiment with the OpenEdge Customization Options. I have checked the option "Send file name of the current selection" and modified the procedure it is calling to have a single input parameter to get the selected file name when it is clicked.
This works great on a single select. When I start messing around with a multi select of files in the project explorer, it only passes the last one selected into the procedure file.
ROUTINE-LEVEL on error undo, throw.
define input parameter ip_cParameters as character no-undo.
{adecomm/oeideservice.i}
/* *************************** Main Block *************************** */
define variable cParamters as character no-undo.
define variable cFileName as character no-undo.
define variable cProjectName as character no-undo.
define variable cProjectDisplayName as character no-undo.
assign
cParamters = entry( 1, ip_cParameters, chr(3) )
cFileName = entry( 2, ip_cParameters, chr(3) )
cProjectName = getProjectName()
cProjectDisplayName = getProjectDisplayName().
message
"Parameters: " cParamters skip(1)
"FileName: " cFileName skip(1)
"Project Name: " cProjectName skip(1)
"Project Display Name: " cProjectDisplayName skip(1)
view-as alert-box title "info".