Вы находитесь на странице: 1из 10

* Sample of sending a HTML-only (using MIME) e-mail message

*
* To compile:
*

Before compiling, change the "from" and "to" e-mail address

info at the top of the source member!

*
*

CRTRPGMOD MODULE(QTEMP/HTMLONLY) +

SRCFILE(xxx/QRPGLESRC) +

DBGVIEW(*LIST)

*
*
*

CRTPGM PGM(&mylib/HTMLmail) +

MODULE(&mylib/HTMLmail) +

BNDSRVPGM(QTCP/QTMMSNDM)

*
*
H BNDDIR('QC2LE') OPTION(*SRCSTMT:*NOSHOWCPY)
fworkfile if

k disk

*-------------------------------------------------------------------* Remove Link to File. (Deletes Directory Entry for File, and if
*

this was the last link to the file data, the file itself is

also deleted)

*
* int unlink(const char *path)
*-------------------------------------------------------------------D unlink
D

path

PR

10I 0 ExtProc('unlink')
*

Value options(*string)

*-------------------------------------------------------------------* Write to a file


*

* ssize_t write(int fildes, const void *buf, size_t bytes)


*-------------------------------------------------------------------D write

PR

D fildes

10I 0 ExtProc('write')
10i 0 value

D buf

D bytes

value

10U 0 value

*-------------------------------------------------------------------* Open a File


*
* int open(const char *path, int oflag, . . .);
*-------------------------------------------------------------------D open

PR

D path

10I 0 ExtProc('open')
*

value options(*string)

D openflags

10I 0 value

D mode

10U 0 value options(*nopass)

D ccsid

10U 0 value options(*nopass)

D/if defined(*V5R2M0)
D txtcreatid

10U 0 value options(*nopass)

D/endif
*-------------------------------------------------------------------* Close a file
*
* int close(int fildes)
*
* Note: Because the same close() API is used for IFS, sockets,
*

and pipes, it's conditionally defined here. If it's

done the same in the sockets & pipe /copy members,

there will be no conflict.

*-------------------------------------------------------------------D close

PR

10I 0 ExtProc('close')

D fildes

10I 0 value

*-------------------------------------------------------------------d QtmmSendMail
d

FileName

FileNameLen

MsgFrom

MsgFromLen

RecipBuf

PR

ExtProc('QtmmSendMail')
255A

const options(*varsize)

10I 0 const
256A

const options(*varsize)

10I 0 const
likeds(ADDTO0100)

dim(32767)

options(*varsize)

NumRecips

ErrorCode

d ADDTO0100

10I 0 const
8000A
ds

options(*varsize)
qualified

based(Template)

NextOffset

10I 0

AddrLen

10I 0

AddrFormat

DistType

10I 0

Reserved

10I 0

SmtpAddr

8A

256A

d ADDR_NORMAL

CONST(0)

d ADDR_CC

CONST(1)

d ADDR_BCC

CONST(2)

D tmpnam

PR

string

*
39A

D MailDate

PR

D CRLF

D filename

50A

D fd

10I 0

extproc('_C_IFS_tmpnam')
options(*omit)

31A
x'0d25'
varying

D header

2000A

varying

D body

32767A

varying

D fromName

100A

varying

D fromAddr

300A

varying

D M_RDWR

const(438)

**********************************************************************
* Flags for use in open()
*
* More than one can be used -- add them together.
**********************************************************************
D O_RDONLY

D O_WRONLY

D O_RDWR

D O_CREAT

D O_EXCL

16

D O_CCSID

32

D O_TEXTDATA

16777216

D O_CODEPAGE

8388608

D O_TEXT_CREAT

33554432

D O_INHERITMODE

134217728

D O_LARGEFILE

536870912

D toName

100A

varying

D toAddr

300A

varying

D subject

80A

varying

D recip

ds

likeds(ADDTO0100)

dim(1)

D NullError

ds

BytesProv

10I 0 inz(0)

BytesAvail

10I 0 inz(0)

D wait

1A

/free

fromName = 'SomeOne';
fromAddr = 'jimmyoctane@code400.com';
toName

= 'testname';

toAddr

= 'jflanary@somedomain.com';

subject = 'Test this';

// -----------------------------------------// create a temporary file in the IFS.


// mark that file as ccsid 819 (ISO 8859-1 ASCII)
// -----------------------------------------filename = %str(tmpnam(*omit));
unlink(filename);
fd = open( filename
: O_CREAT+O_EXCL+O_WRONLY+O_CCSID
: M_RDWR
: 819 );
if (fd = -1);
//*ERROR
endif;
// -----------------------------------------// close file & reopen in text mode so that
// data will be automatically translated
// -----------------------------------------callp close(fd);
fd = open( filename : O_WRONLY + O_TEXTDATA );
if (fd = -1);
//*ERROR

endif;
// -----------------------------------------// build an e-mail header in a variable
// -----------------------------------------header =
'From: ' + fromName + ' <' + fromAddr + '>' + CRLF
+'To: '

+ toName

+ ' <' + toAddr

+ '>' + CRLF

+'Date: ' + maildate() + CRLF


+'Subject: ' + subject + CRLF
+'MIME-Version: 1.0' + CRLF
+'Content-Type: text/html' + CRLF
+ CRLF;
// -----------------------------------------// put the message text into a variable
// -----------------------------------------body =
'<html>' + CRLF
+'<LINK href="http://www.code400.com/code400.css" rel=stylesheet>'
+ CRLF
+ '<img src="http://www.code400.com/images/code400.gif">'
+ CRLF
+'<head>' + CRLF
+'<style type="text/css">' + CRLF
+'.red {font-size: 14pt; font-family: Arial; '
+'color: #ff0000;}' +CRLF
+'.normal {font-size: 14pt; font-family: Arial;}' + CRLF
+'.emphasis {font-style: italic;' + CRLF
+'

font-weight: bold;' + CRLF

+'

font-size: 14pt;'

+'

font-family: Arial;}'+ CRLF

+ CRLF

+'</style>' + CRLF
+'</head>' + CRLF
+'<body>'

+ CRLF

+'<p class="headlineorange">Table: WorkFILE</p>' + CRLF


+'<i>Jimmy Octane</i></p>' + CRLF
+'<td >' + CRLF
+'<ul>' + CRLF;

read workfile;
dow not%eof(workfile);
body = %trim(body) + '<li> ' + ' <b>' +
%trim(claim) + '</b> : ' + %editc(amount:'J') + '<BR><BR>'
+ CRLF;
read workfile;
enddo;

body = %trim(body)
+'</ul></td>' + CRLF
+ ' <A href="mailto:jflanary@somedomain.com">Comments</A>'
+'</body>' + CRLF
+'</html>' + CRLF;
// -----------------------------------------// write the data to the IFS file
// (since the file is in text mode, it'll
//

automatically be translated to ASCII )

// -----------------------------------------callp write(fd: %addr(header)+2: %len(header));


callp write(fd: %addr(body)+2: %len(body));
callp close(fd);
// ------------------------------------------

// Use the QtmmSendMail() API to send the


// IFS file via SMTP
// -----------------------------------------recip(1).NextOffset = %size(ADDTO0100);
recip(1).AddrFormat = 'ADDR0100';
recip(1).DistType

= ADDR_NORMAL;

recip(1).Reserved

= 0;

recip(1).SmtpAddr

= toAddr;

recip(1).AddrLen

= %len(toAddr);

QtmmSendMail( FileName
: %len(FileName)
: fromAddr
: %len(fromAddr)
: recip
: %elem(recip)
: NullError );
*inlr = *on;

/end-free

*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* MailDate(): Returns the current date, formatted for use
*

in an e-mail message.

*
*

For example: 'Sat, 23 Oct 2004 14:42:06 -0500'

*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P MailDate

D MailDate

PI

D CEELOCT

PR

31A

opdesc

Lilian

10I 0

Seconds

8F

Gregorian

23A

fc

12A

D CEEUTCO

PR

opdesc

Hours

10I 0

Minutes

10I 0

Seconds

8F

fc

D CEEDATM

options(*omit)

12A

PR

options(*omit)

opdesc

input_secs

8F

date_format

80A

const options(*varsize)

char_date

80A

options(*varsize)

feedback

12A

options(*omit)

D rfc2822

D junk1

8F

D junk2

10I 0

D junk3

23A

D hours

10I 0

D mins

10I 0

D tz_hours

2P 0

D tz_mins

2P 0

D tz

5A

D CurTime

8F

D Temp

25A

/free

const

'Www, DD Mmm YYYY HH:MI:SS'

varying

//
// Calculate the Timezone in format '+0000', for example
//

CST should show up as '-0600'

CEEUTCO(hours: mins: junk1: *omit);


tz_hours = %abs(hours);
tz_mins = mins;

if (hours < 0);


tz = '-';
else;
tz = '+';
endif;

tz += %editc(tz_hours:'X') + %editc(tz_mins:'X');
//
// Get the current time and convert it to the format
//

specified for e-mail in RFC 2822

//
CEELOCT(junk2: CurTime: junk3: *omit);
CEEDATM(CurTime: rfc2822: Temp: *omit);
return Temp + ' ' + tz;

/end-free

Вам также может понравиться