Sie sind auf Seite 1von 8

************************************************************************

*
*
*
*
*
Modification Log
*
*----------------------------------------------------------------------*
* 03/10/2004 | Raymond Everhart | 000 | Program Created
*
*
|
|
|
*
*
|
|
|
*
*
|
|
|
*
*
|
|
|
*
************************************************************************
*
*
D* Prototype used by QTMMSENDMAIL API
D SndEmail
PR
Extproc('QtmmSendMail')
D IFSFile
* value
D FNameLen
10i 0
D Sender
* value
D SenderLen
10i 0
D RecipTbl
* value
D NbrRecips
10i 0
D pErr
* value
* copy error structure from QSYSINC
D/copy qsysinc/qrpglesrc,qusec
D Qdata
17
216
D
* set pointer to Error structure
D pErr
S
*
D
* email variables
D Cmd
S
256a
D CmdLen
S
15 5
D RecipTbl
S
32767a
D IFSFile
S
255a
D inetAddr
S
256a
D FNameLen
S
10i 0
D ListPtr
S
*
D Sender
S
256a
D SenderLen
S
10i 0
D NbrRecips
S
10i 0
D Text
S
80
D ToAddr
S

Inz(%addr(QUSEC))

Inz('/email/mimefile.txt')
Inz(%Addr(RecipTbl))

Like(iNetAddr)

* ADDT0100 data structure - (See IBM Qtmmsendmail docs for details)


*
D ADDT0100
DS
Based(ListPtr)
D NextOffset
9b 0
D AddrLen
9b 0
D AddrFmt
8
D DistType
9b 0
D Resrvd01
9b 0
D DestAddr
256
D
D
D
D
D

From
To
CC
BC
Quote

C
C
C
C
C

Const('errors@morningstarfoods.com')
Const('AllCustomers@Lab400.com')
Const('CarbonCopy@Lab400.com')
Const('BlindCopy@Lab400.com')
Const('''')

C* Initialize Error structure parms


C
Eval
Qusbavl = 0
C
Eval
Qusbprv = 216
C
Exsr
Build file in QTEMP
C
Exsr
Send To Address
C
Exsr
CC addresses
C
Exsr
BC addresses
C
Exsr
From Address
C
Exsr
Write email header
C
Exsr
Write out email body
C
Exsr
write out email footer
C
Exsr
Move work file to the IFS
C
Exsr
Send the email
C

Eval

BuildFile
SendTo
SendCC
SendBC
SendFrom
Header
Body
Footer
Move2IFS
SendEmail
*INLR = *On

**************************************************************************
/Eject
**************************************************************************
C
*Inzsr
Begsr
C

Eval

FNameLen = %Len(%Trim(IFSFile))

Endsr
**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Write the email Body lines from the Mailform File
* (Notice how much easier it is to code these statements in Free Format RP
G)
*
/FREE
Begsr Body;
// First Row
Text = '<TR><TD ALIGN="Left">M465043</TD>';
Exsr WriteText;
Text = '<TD ALIGN="Left">Roys Sandwich Shoppe</TD>';
Exsr WriteText;
Text = '<TD ALIGN="Right">03/15/2004</TD>';
Exsr WriteText;
Text = '<TD ALIGN="Right">1,245.55</TD></TR>';
Exsr WriteText;
// Second Row
Text = '<TR><TD ALIGN="Left">M464657</TD>';

Exsr
Text
Exsr
Text
Exsr
Text
Exsr

WriteText;
= '<TD ALIGN="Left">That Sub Place</TD>';
WriteText;
= '<TD ALIGN="Right">03/19/2004</TD>';
WriteText;
= '<TD ALIGN="Right">1,455.85</TD></TR>';
WriteText;

// Third Row
Text = '<TR><TD ALIGN="Left">M557890</TD>';
Exsr WriteText;
Text = '<TD ALIGN="Left">Harrys House of Hoagies</TD>';
Exsr WriteText;
Text = '<TD ALIGN="Right">03/22/2004</TD>';
Exsr WriteText;
Text = '<TD ALIGN="Right">6,685.55</TD></TR>';
Exsr WriteText;
EndSr;
/END-FREE
**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Build a file in QTEMP to format the email message
*
C
BuildFile
Begsr
*
C* Create an Empty WorkFile
C/Exec SQL
C+ Create table QTEMP/EMAIL
C+ (TEXT CHAR (80 ) NOT NULL WITH DEFAULT)
C/End-Exec
* Delete any records left in file from a previous run
C/Exec SQL
C+ Delete from QTEMP/EMAIL
C/End-Exec
C
EndSr
**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Write Out Email Footer
*
C
Footer
Begsr
* Write the end tag for the table
Eval
Text = '</TABLE>'
Exsr
WriteText

C
C

* Write the end of report text


Eval
Text = '<P>END
Exsr
WriteText

C
C

* Write the end tag for the page

OF

REPORT'

C
C

Eval
Exsr

EndSr

Text = '</body></HTML>'
WriteText

**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Write the Header lines
*
C
Header
Begsr
* Write the From Address
Eval

C
C
C
C

Exsr
* Write the To Address
Eval

C
C
C
C

Exsr
* Write the Subject Line
Eval

C
C
C

Exsr

Text = 'From: ' +


'"Spotlight Magazine" ' +
'<' + From + '>'
WriteText
Text = 'To: ' +
'"Subscriber" ' +
'<' + To + '>'
WriteText
Text = 'Subject: ' +
'HTML Based Email from the iSeries'
WriteText

* Write the Date the email was sent


Eval
Text = 'Date: ' +
%Editc(*Date:'Y')
Exsr
WriteText

C
C
C
C

* Write the Mime Version


Eval
Exsr

C
C

* Write the Content Line


Eval

C
C
C

Exsr
* Write a blank Line
Eval
Exsr

C
C

Text = 'Mime-Version: 1.0'


WriteText
Text = 'Content-Type: Text/HTML; ' +
'charset=US-ASCII'
WriteText
Text = ' '
WriteText

* Write the beginning of the page description


Eval
Text = '<HTML><BODY>'
Exsr
WriteText

C
C

* Define a table for the image file and text header


Eval
Text = '<table><tr>' +
'<TD A HREF="http://www.as400.ibm.com">'
Exsr
WriteText
Eval
Text = '<img src="http://www-1.ibm.com/' +
'servers/eserver/iseries/hardware' +

C
C
C
C
C

C
C
C
C
C
C
C
C
C
C
C

Exsr
Eval
Exsr
Eval
Exsr
Eval
Exsr
Eval
Exsr

'/graphics/'
WriteText
Text = 'iseries_family.jpg">'
WriteText
Text = '</td><td><FONT SIZE=5>'
WriteText
Text ='HTML formatted Email <br>' +
'from the iSeries'
WriteText
Text ='</font></td></tr></table><br>'
WriteText

* Define a table and the header row for the report


Eval
Text ='<TABLE BORDER><TR>'
Exsr
WriteText
Eval
Text ='<TD BGCOLOR="#00ffff"
+ 'ORDER NUMBER</TD>'
Exsr
WriteText
Eval
Text ='<TD BGCOLOR="#00ffff"
+ 'CUSTOMER</TD>'
Exsr
WriteText
Eval
Text ='<TD BGCOLOR="#00ffff"
+ 'SHIP DATE</TD>'
Exsr
WriteText
Eval
Text ='<TD BGCOLOR="#00ffff"
+'ORDER VALUE</TD>'
Exsr
WriteText
Eval
Text ='</TR>'
Exsr
WriteText

C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C

align="center">'
align="center">'
align="center">'
align="center">'

EndSr

**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Move the file to the IFS and change the user authority to the file
*
*
C
Move2IFS
Begsr
C
C
C
C
C
C
C
C
C
C
C

Eval

Call
Parm
Parm

'QCMDEXC'

C
C
C
C
C
C

Eval

Cmd = 'CHGAUT OBJ(' + Quote +


%Trim(IFSFile) + Quote + ') '
+ 'USER(QTCP QMSF)'
+ ' DTAAUT(*RWX)'
+ ' OBJAUT(*ALL)'

Eval

Cmd = 'CPYTOIMPF FROMFILE(QTEMP/EMAIL) ' +


'TOSTMF(' + Quote + %Trim(IFSFile) +
Quote + ') ' +
'MBROPT(*REPLACE) ' +
'STMFCODPAG(*PCASCII) ' +
'RCDDLM(*CRLF) DTAFMT(*FIXED)'
CmdLen = %Len(%Trim(Cmd))
Cmd
CmdLen

Eval

CmdLen = %Len(%Trim(Cmd))

C
C
C
C

Call
Parm
Parm
EndSr

'QCMDEXC'
Cmd
CmdLen

**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Retreive the Blind Copy (BC) addresses from the Mailform File
*
*
C
SendBC
Begsr
C* load recipients into table (blind copy)
C
C
C
C
C
C
C

Eval
Eval
Eval
Eval
Eval
Eval
Eval
* Move the DS Pointer
Eval

C
C

DistType = 2
DestAddr = BC
Addrfmt = 'ADDT0100'
Resrvd01 = 0
Addrlen = %len(%trim(DestAddr))
NextOffset = 24 + Addrlen
NbrRecips = NbrRecips + 1
ListPtr = ListPtr + NextOffset

EndSr

**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Retreive the Carbon Copy (CC) addresses from the Mailform File
*
*
C
SendCC
Begsr
C* load recipients into table (carbon copy)
C
C
C
C
C
C
C

Eval
Eval
Eval
Eval
Eval
Eval
Eval
* Move the DS Pointer
Eval

C
C

DistType = 1
DestAddr = CC
Addrfmt = 'ADDT0100'
Resrvd01 = 0
Addrlen = %len(%trim(DestAddr))
NextOffset = 24 + Addrlen
NbrRecips = NbrRecips + 1
ListPtr = ListPtr + NextOffset

EndSr

**************************************************************************
********************
C/Eject

**************************************************************************
********************
* Retreive the From address from the Mailform File
*
*
C
SendFrom
Begsr
C* load from address into table
C
C

Eval
Eval

EndSr

Sender = From
SenderLen = %len(%trim(Sender))

**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Retreive the Send To address from the Mailform File
*
*
C
SendTo
Begsr
C* load first recipient into table
C
C
C
C
C
C
C

Eval
Eval
Eval
Eval
Eval
Eval
Eval
* Move the DS Pointer
Eval

C
C

DistType = 0
DestAddr = To
Addrfmt = 'ADDT0100'
Resrvd01 = 0
Addrlen = %len(%trim(DestAddr))
NextOffset = 24 + Addrlen
NbrRecips = 1
ListPtr = ListPtr + NextOffset

EndSr

**************************************************************************
********************
C/Eject
**************************************************************************
********************
* Send the email via the API. When the API completes normally, the IFS fi
le is deleted.
C

SendEmail

C* Send the email


C
IFS Filename
C
Length of IFS File
C
From Address
C
From Address Length
C
Recipient list

Begsr
Callp

SndEmail(%addr(IFSFile):
FNameLen:
%addr(Sender):
SenderLen:
%addr(RecipTbl):

C
Number of Recipients
C
Error Structure
C

NbrRecips:
pErr)
EndSr

**************************************************************************
/Eject
**************************************************************************
*
C
WriteText
Begsr
C/Exec SQL
C+ Insert into Qtemp/EMAIL
C+ VALUES(:Text)
C/End-Exec
C

EndSr

Das könnte Ihnen auch gefallen