send an email using progress code

Cecil

19+ years progress programming and still learning.
Which version of Progress/OpenEdge do you have?
Which OS in the client running on that needs the send the email? Windows or Unix/Linux?
Did you want to send the email via an SMTP or MAPI (MS Exchange) server?
 

rajesh4you

New Member
Hi Cecil,

I am using progress 9.1D and UNIX system.
I got the code

UNIX SILENT echo "body" | mailx -s "subject" "emailid@domain.com".

But I am having a problem with the below code.

UNIX SILENT echo "body" | uuencode file1 file1 | | mailx -s "subject is here" "emailid@domain.com".

When I execute this code the email will go to is@domain.com, here@domain.com and emailid@domain.com i.e., the subject will be only one work. It is not a string of words and one more thing to highlight is when I attach the file1 as atttachment - this time the body will not get display.

When I execute the same code from UNIX prompt it works. I think the code is behaving strange.
 

sunilnair

Member
use smtpmail.p it does the job and is free , you can get it from
http://www.freeframework.org/downloads/new/smtpmail/
progress.gif
 

rajesh4you

New Member
hi sphipp,

ya the link is broken and the code is working thank you.
I need a slight modification. Can you modify the same code to have body for the email. Thank you.
 

sphipp

Member
This should work OK. The first block contains some sample code to run the program.

Code:
RUN unixemail.p("./TemporarySendEmailScript.sh":U, 
                cEmailSubject,
                cEmailList,
                cEmailText,
                cEmailFullName).

Code:
RUN UnixEmail.p("./TemporarySendEmailScript.sh":U, 
                "Email From Unix,
                "someone@mycompany.com,someoneelse@mycompany.com",
                "Hello" + chr(10) + "This is an automatic email" + chr(10) + "generated by " + chr(10) + chr(10),
                 "/mypath/myreportfile.txt," + "/mypath/anotherreportfile.txt").


Don't forget that Unix is case-sensitive, so you need to run unixemail.p not UnixEmail.p, for example.

You could insert Unix shell script calls into the body of the email, if you wanted, but this can cause the script to fall over, so I wouldn't bother.

Hope this helps.

Code:
/*------------------------------------------------------------------
    File        : unixemail.p
    Purpose     : Send Unix Email with Attachments and Text
    Syntax      : RUN unixemail("./TemporarySendEmailScript.sh":U, 
                    cEmailSubject,
                    cEmailList,
                    cEmailText,
                    cEmailFullName).
 
                 RUN unixemail("./TemporarySendEmailScript.sh":U, 
                    "Email From Unix,
                    "someone@mycompany.com,someoneelse@mycompany.com",
                    "Hello" + chr(10) + "This is an automatic email" + chr(10) + "generated by " + chr(10) + chr(10),
                    "/mypath/myreportfile.txt," +
                    "/mypath/anotherreportfile.txt").   
 
    Parameters  :  pi_cEmailScript - temporary script name 
                                     This is a throw-away script and is deleted
                                     so should be a long and unusual name
 
                   pi_cSubject     - The email subject, no quotes, please
 
                   pi_cRecipient   - A comma-delimited list of valid email
                                     addresses, not validated
 
                   pi_cText        - The body text of the email, break this
                                     down into lines using \n. This can have
                                     all kinds of Unix goodness if you want.
 
                   pi_cFileList    - A comma-delimited list of filenames to 
                                     be sent as attachments. These can be relative 
                                     filenames as the program will pull the full
                                     path. It also tags these on to the end of
                                     the email body as Attachment: filename.
                                     If this is blank then no attachments are sent.
                                     If the individual files do not exist then 
                                     that entry in the list is not sent as an 
                                     attachment.
 
    Description :  This is a program to send Email from Unix.
                   It will attach files in a comma-delimited list and can
                   give the email some text explaining what the files are for.
    Author(s)   : Simon Phipp
    Created     : July 2008
    Notes       : This generates and executes a script to send an email on Unix
                  using mailx.
                  The email body can contain valid Unix code inside `` marks
                  in order to put in information from Unix, but be careful as
                  incorrect Unix shell scripting can break the mail script.
 
  --------------------------------------------------------------*/
 
 
    DEFINE INPUT  PARAMETER pi_cEmailScript AS CHARACTER  NO-UNDO.
    DEFINE INPUT  PARAMETER pi_cSubject     AS CHARACTER  NO-UNDO.
    DEFINE INPUT  PARAMETER pi_cRecipient   AS CHARACTER  NO-UNDO.
    DEFINE INPUT  PARAMETER pi_cText        AS CHARACTER  NO-UNDO.
    DEFINE INPUT  PARAMETER pi_cFileList    AS CHARACTER  NO-UNDO.
 
 
FUNCTION lastentry RETURNS CHARACTER
  ( pi_clist AS CHARACTER , pi_cdelim AS CHARACTER)  FORWARD.
IF OPSYS = "unix" THEN RUN ipSendEmail.
 
 
PROCEDURE ipFileInfo :
    DEFINE INPUT  PARAMETER pi_cFileName AS CHARACTER  NO-UNDO.
    DEFINE OUTPUT PARAMETER po_cLongName AS CHARACTER  NO-UNDO.
    DEFINE OUTPUT PARAMETER po_cShortName AS CHARACTER  NO-UNDO.
    ASSIGN FILE-INFO:FILE-NAME = pi_cFileName
           po_cLongName = FILE-INFO:FULL-PATHNAME
           po_cShortName = lastentry (po_cLongName,(IF OPSYS = "unix":U THEN "/":U ELSE CHR(92))).
END PROCEDURE.
PROCEDURE ipSendEmail :
    DEFINE VARIABLE         iemailloop      AS INTEGER    NO-UNDO.
    DEFINE VARIABLE         cEmailEntry     AS CHARACTER  NO-UNDO.
    DEFINE VARIABLE         cEmailFile      AS CHARACTER  NO-UNDO.
    DEFINE VARIABLE         cEmailCommand   AS CHARACTER  NO-UNDO.
    DEFINE VARIABLE         cAttachList     AS CHARACTER  NO-UNDO.
    DEFINE VARIABLE         cUuencodeList   AS CHARACTER  NO-UNDO.
    ASSIGN pi_cEmailScript = REPLACE (pi_cEmailScript," ":U,"":U)
           cemailcommand = 
               "mailx -r [EMAIL="fromme@mycompany.com"]fromme@mycompany.com[/EMAIL] -s ""<sub>"" <list>  <<EOF":U.
    DO iemailloop = 1 TO NUM-ENTRIES(pi_cFilelist):
        ASSIGN cemailentry = ENTRY (iemailloop,pi_cfilelist).
        IF SEARCH (cemailentry) = ? THEN NEXT.
        RUN ipFileInfo (INPUT  cemailentry,
                        OUTPUT cemailentry,
                        OUTPUT cemailfile).
        ASSIGN cAttachlist   = cAttachlist + 
                               (IF cAttachList = "":U THEN "":U ELSE CHR(10)) +
                               "Attachment: ":U + cemailfile
               cUuencodeList = cuuencodelist + 
                               (IF cUuencodeList = "":U THEN "":U ELSE CHR(10)) +
                               "`cat ":U + cemailentry + 
                               " | uuencode ":U + cemailfile + " `":U.
    END.
    OUTPUT TO VALUE (pi_cEmailScript).
    ASSIGN cemailcommand = 
        REPLACE(REPLACE (cemailcommand,"<sub>":U,pi_csubject),
            "<list>":U,pi_crecipient).
 
    PUT UNFORMATTED 
        cemailcommand
        SKIP
        pi_ctext SKIP
        cAttachlist SKIP
        cUuencodelist SKIP
        "EOF":U SKIP(1).
    OUTPUT CLOSE.
    ASSIGN FILE-INFO:FILE-NAME = pi_cemailscript
           pi_cemailscript     = FILE-INFO:FULL-PATHNAME.
    OS-COMMAND SILENT VALUE("chmod 777 ":U + pi_cemailscript).
    OS-COMMAND SILENT VALUE(pi_cemailscript).
    OS-DELETE         VALUE (pi_cemailscript).
END PROCEDURE.
 
 
FUNCTION lastentry RETURNS CHARACTER
  ( pi_clist AS CHARACTER , pi_cdelim AS CHARACTER) :
IF pi_clist = "" THEN 
    RETURN "".
ELSE
    RETURN ENTRY (NUM-ENTRIES (pi_clist,pi_cdelim),pi_clist,pi_cdelim).
END FUNCTION.
 

ezequiel

Member
Hi, this is not exactly the question; I need to send mail in windows, using Outlook or MAPI; my problem are the warning safety messages that Outlook shows before sending the mail.

Do you know if there is a way to avoid these messages?


Thank you
 

ezequiel

Member
Thank you, Casper. I had read about Redemption in another thread but I was (well, I am) afraid of using this misterious DLL, is it safe?
 

Casper

ProgressTalk.com Moderator
Staff member
Yes, it is safe. You even get decent support, in case you run into troubles.

Casper.
 

Kevin Williams

New Member
I happen to use this to perform the send functions from our system.

Code:
def var mailopt as char.


/* Normal Email */
mailopt = "-s 'This is the Email Subject Line' email@something.com,another@something.com".

output thru value("sed 's/$/~015/' | uuencode systeminputfilename.csv outgoingattachmentfilename.csv | mailx " + mailopt).

output close.
 
Top