SMTPMailServiceの例
これは、メールを構成して送信する簡単なファンクションです。このファンクションでは、メールへの添付ファイルの追加はサポートされません。
Uses Integrator Services: SMTPMAILSERVICE
* This forms allows you to format and send a simple email using the SMTP protocol.
* The following fields must be defined in your data dictionary to support this function:
* jsmemail char 250
* jsmsts alpha 20
* jsmmsg alpha 255
* jsmhdle char 500
* jsmcmd alpha 4
* Beginning of RDML commands **********
function options(*DIRECT)
begin_com role(*EXTENDS #PRIM_FORM) clientheight(414) clientwidth(585) height(448) left(471) top(168) width(593)
define_com class(#PRIM_STBR) name(#STBR_1) displayposition(9) height(24) left(0) messageposition(1) parent(#COM_OWNER) tabposition(9) tabstop(False) top(390) width(585)
define_com class(#JSMEMAIL.Visual) name(#toaddress) caption('To') displayposition(1) labeltype(Caption) left(8) marginleft(80) parent(#COM_OWNER) tabposition(1) top(8)
define_com class(#JSMEMAIL.Visual) name(#ccaddress) caption('CC') displayposition(2) labeltype(Caption) left(8) marginleft(80) parent(#COM_OWNER) tabposition(2) top(32)
define_com class(#JSMEMAIL.Visual) name(#Subject) caption('Subject') displayposition(3) labeltype(Caption) left(8) marginleft(80) parent(#COM_OWNER) tabposition(3) top(56)
define_com class(#JSMEMAIL.Visual) name(#fromaddress) caption('From Address') displayposition(8) labeltype(Caption) left(8) marginleft(80) parent(#COM_OWNER) tabposition(8) tabstop(False) top(80) visible(False) width(3)
define_com class(#JSMEMAIL.Visual) name(#fromname) caption('From Name') displayposition(4) labeltype(Caption) left(8) marginleft(80) parent(#COM_OWNER) tabposition(4) tabstop(False) top(104) visible(False) width(3)
define_com class(#PRIM_PHBN) name(#Send) caption('Send') displayposition(6) left(24) parent(#COM_OWNER) tabposition(6) top(360) width(100)
define_com class(#PRIM_PHBN) name(#Reset) caption('Reset') displayposition(7) left(136) parent(#COM_OWNER) tabposition(7) top(360) width(100)
define_com class(#PRIM_MEMO) name(#message) componentversion(1) currentline(1) displayposition(5) height(273) left(8) maximumlinelength(250) parent(#COM_OWNER) showselectionhilight(False) tabposition(5) top(80) width(553) wordwrap(True)
define_com class(#PRIM_MECL) name(#messageline) columnrole(Data) displayposition(1) parent(#message) source(#JSMEMAIL)
define field(#pos) type(*dec) length(3) decimals(0)
define field(#start) type(*dec) length(3) decimals(0)
define field(#filename) type(*char) length(255)
def_list name(#filelist) fields(#filename) type(*Working)
def_list name(#tolist) fields(#jsmemail) type(*Working)
def_list name(#cclist) fields(#jsmemail) type(*Working)
evtroutine handling(#com_owner.Initialize)
set com(#com_owner) caption(*component_desc)
#jsmhdle := *default
#fromaddress := [email protected]
#fromname := 'LANSA Product Centre'
* Start JSM Server on IBM
i
use builtin(jsmx_open) with_args('ISERIES01:4570') to_get(#jsmsts #jsmmsg #jsmhdle)
* Start local JSM server
* use builtin(jsmx_open) with_args('localhost:4560') to_get(#jsmsts #jsmmsg #jsmhdle)
* execute subroutine(check) with_parms(#jsmsts #jsmmsg)
* Load the service
#jsmcmd := 'Service_Load Service(SMTPMailService) trace(*yes)'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
endroutine
mthroutine name(SendEmail)
if (*Not #jsmhdle.isnull)
* from details (ideally these should be set up in your SMTPMailService.properties file)
#jsmcmd := 'set from(' + #fromaddress + ') from_name(' + #fromname + ')'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
* Set the to address(es)
clr_list named(#tolist)
#start := 1
dountil (#pos = 0)
if (#toaddress.cursize > #start)
#pos := #toaddress.positionof( ';', #start )
else
#pos := 0
endif
if (#pos = 0)
#jsmemail := #toaddress.substring( #start )
else
#jsmemail := #toaddress.substring( #start, (#pos - #start) )
#start := #pos + 1
endif
if (#jsmemail *NE *blank)
add_entry to_list(#tolist)
endif
enduntil
use builtin(jsmx_command) with_args(#jsmhdle 'set to(*list) ') to_get(#jsmsts #jsmmsg #tolist)
#com_owner.check( #jsmsts #jsmmsg )
* Set the cc address(es)
clr_list named(#cclist)
#start := 1
dountil (#pos = 0)
if (#ccaddress.cursize > #start)
#pos := #ccaddress.positionof( ';', #start )
else
#pos := 0
endif
if (#pos = 0)
#jsmemail := #ccaddress.substring( #start )
else
#jsmemail := #ccaddress.substring( #start, (#pos - #start) )
#start := #pos + 1
endif
if (#jsmemail *NE *blank)
add_entry to_list(#cclist)
endif
enduntil
use builtin(jsmx_command) with_args(#jsmhdle 'set cc(*list)') to_get(#jsmsts #jsmmsg #cclist)
#com_owner.check( #jsmsts #jsmmsg )
* add attachments
clr_list named(#filelist)
#filename := order.xml
add_entry to_list(#filelist)
#filename := message01.txt
add_entry to_list(#filelist)
#filename := test-input/thankyou.pdf
add_entry to_list(#filelist)
* #jsmcmd := 'add attachment(*list) zip(orderstatus.zip)'
#jsmcmd := 'add attachment(*list)'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg #filelist)
#com_owner.check( #jsmsts #jsmmsg )
* Send mail
#jsmcmd := 'send subject(' + #subject + ')'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg #message)
#com_owner.check( #jsmsts #jsmmsg )
endif
endroutine
* send the email
evtroutine handling(#Send.Click)
#com_owner.SendEmail
endroutine
* reset the email variables
evtroutine handling(#Reset.Click)
clr_list named(#message)
#toaddress #ccaddress #subject := *blank
endroutine
* check the JSM return status
mthroutine name(check)
define_map for(*input) class(#jsmsts) name(#i_status)
define_map for(*input) class(#jsmmsg) name(#i_message)
message
msgtxt(#i_status + ' :' +
#i_message)
endroutine
evtroutine handling(#com_owner.closing) options(*noclearmessages *noclearerrors)
* Unload service
use builtin(jsmx_command) with_args(#jsmhdle 'Service_Unload') to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
* Close the thread
use builtin(jsmx_close) with_args(#jsmhdle) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
endroutine
end_com