CAFE

③ T & E & F

[[TIP]]피비로 멜보내기

작성자우처리|작성시간02.08.01|조회수771 목록 댓글 0
내용:

script:
첫째 Text입력은 SingleLineEdit
메일보내기
integer lv_iStart = 1, lv_iEnd
String lv_sText, lv_sTemp, lv_sdate

lv_sText = Trim(sle_Male.Text)

IF lv_sText = '' THEN
MessageBox("확인","수신처를 입력바랍니다")
Return
END IF

lv_sdate = String(Today(), "yyyymmdd")
DO
lv_iEnd = Pos(lv_sText, ';', lv_iStart)
lv_sTemp = Mid(lv_sText, lv_iStart, lv_iEnd - lv_iStart)
IF lv_sTemp = '' THEN Exit
INSERT INTO IL_MALE
(il_yyyymmdd, il_name, il_text)
VALUE
(lv_sdate, lv_sTemp, lv_sMleText);
IF sqlca.sqlcode = 0 THEN
Commit;
ELSE
RollBack;
END IF
lv_iStart = lv_iEnd + 1
LOOP UNTIL lv_iEnd < 1
MessageBox("메일전송","메일이 전송되었습니다.")

참조:
E-Mail이 PowerBuilder 어플리케이션에 통합될 수 있는 방법으로는 다음과 같은 4가지를 들 수 있다.

PowerBuilder의 DDE 인터페이스
PowerBuilder의 MAPI 인터페이스
Lotus Notes PowerBuilder 라이브러리
E-Mail API

윈도우 환경에서 E-Mail API 표준으로는 Microsoft사의 Messaging API ( MAPI )와 IBM, Apple, Borland, Novell사 등에서 지원하는 Vendor independent messaging ( VIM ), 그리고 OSI 표준인 X.400을 들 수 있다.

l PowerBuilder의 DDE 인터페이스
PowerBuilder 어플리케이션에서 가장 손쉽게 E-Mail 인터페이스를 구현하는 방법은 DDE를 사용해서 다른 E-Mail 시스템과 직접 통신하는 방법이다. 예를 들어 그림 1과 같은 PowerBuilder 윈도우를 사용해서 Lotus Notes 메세지를 보낼 수 있다.

DDE를 사용하는 경우 윈도우의 Open Event와 버튼의 Clicked Event에 각각 다음과 같은 스크립트를 작성하면 된다.

Open Event ( w_interface )

/**************************************************************************
** WIN.INI에서 Notes 프로그램의 이름을 읽어와서 인스턴스 변수
** i_sMailExe에 저장한다
**************************************************************************/

// Notes가 설치되었는지 확인한다
if UPPER ( ProfileString ( "WIN.INI", "LotusMail", "Application", &
"") ) < > "NOTES" then
MessageBox ( "Error", "Notes Not Installed", StopSign! )
Halt Close
end if

i_sMailExe = ProfileString ( "WIN.INI", "LotusMail", "Program", "" )
if i_sMailExe = "" then
MessageBox ( "Error", "Notes Not Installed", StopSign! )
Halt Close
end if



그림 1



Clicked Event ( cb_send )

/**************************************************************************
** Notes로 메세지를 보낸다.
**************************************************************************/

int iRtn, iHndl, iSendCnt, iAttacCnt
time tStartTime

SetPointer ( HourGlass! )
// Notes와 Channel을 연다
iHndl = OpenChannel ( "Notes", "SendMail" )

// Notes가 실행되어 있지 않으면 기동시킨다
if iHndl < 1 then
Run ( i_sMailExe, Minimized! )
tStartTime = Now ( )
Do
Yield ( )
iHndl = OpenChannel ( "Notes", "SendMail" )
if iHndl > 0 then Exit
Loop until SecondsAfter ( tStartTime, Now ( ) ) > 120
if iHndl < 1 then
MessageBox ( "Error". "Cannot start Notes", StopSign! )
SetPointer ( Arrow! )
Return
end if
end if

// Notes가 기동되어 있으면 새 메세지를 작성한다.
iRtn = ExecRemote ( "NewMessage", iHndl )

// To: 리스트에 있는 사람들에게 메세지를 보낸다.
for iSendCnt = 1 to lb_to.totalitems ( )
iRtn = ExecRemote ( "To " + lb_to.item [iSendCnt], iHndl )
sle_message.text = "Message sent to: " + lb_to.item [iSendCnt]
next

// cc: 리스트에 있는 사람들에게 메세지를 보낸다.
for iSendCnt = 1 to lb_cc.totalitems ( )
iRtn = ExecRemote ( "To " + lb_cc.item [iSendCnt], iHndl )
sle_message.text = "Message sent to: " + lb_cc.item [iSendCnt]
next

// Subjec와 메세지 텍스트를 보낸다.
iRtn = ExecRemote ( "Subject " + sle_subject.text, iHndl )
iRtn = ExecRemote ( "Text " + mle_note.text, iHndl )

// Attachment를 보낸다.
for iAttachCnt = 1 to lb_attach.totalitems ( )
iRtn = ExecRemote ( "AttachFile " + lb_attach.item [iAttachCnt], & iHndl )
next

// 메세지를 보내고 Channel을 닫는다.
iRtn = ExecRemote ( "Send", iHndl )
iRtn = CloseChannel ( iHndl )
SetPointer ( Arrow! )


l PowerBuilder의 MAPI 인터페이스

PowerBuilder에는 MAPI를 사용 하기 위하여 MailSession 이라는 오브젝트를 제공하며 다음과 같은 속성을 가진다.

SessionID
MessageID[ ]


MAPI를 사용하기 위한 구조체 :

?mailFileDescription - Attachment의 정보를 저장하기 위한 구조체로 다음과 같은 속성을 갖는다.

Attribute Data Type
FileName String
PathName String
FileType mailFileType ( enumerated )
Position Unsigned Long

? mailMessage - Message 정보를 저장하기 위한 구조체로 다음과 같은 속성을 갖는다.

Attribute Data Type
ReceiptRequested Boolean
MessageSent Boolean
Unread Boolean
Subject String
NoteText String
MessageType String
DateReceived String
ConversationID String
Recipient[ ] mailRecipient array
AttachmentFile[ ] mailFileDescription array

? mailRecipient - 발신자와 수신자의 정보를 저장하는 구조체로 다음과 같은 속성을 갖는다.

Attribute Data Type
Name String
Address String
mailRecipientType mailRecipientType ( enumerated )
EntryType Protected blob


MAPI를 위한 함수들 :

?mailAddress ( mailmessage )

mailRecipient array를 수정한다. Mailmessage 매개변수는 선택적이며 없을 때는 주소의 리스트가 디스플레이 된다. 이 함수의 리턴 값은 다음 중 하나이다.

n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!
n mailReturnUserAbort!

? mailDeleteMessage ( messageid )

messageid는 String type으로 삭제 될 message의 ID를 나타내며 이것은 mailGetMessates ( )라는 함수를 통해 얻을 수 있다. mailDeleteMessage ( )가 리턴하는 값은 다음 중 하나이다.

n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!
n mailReturnUserAbort!
n mailReturnInvalidMessage!

? mailGetMessages ( returnunreadonly )

MailSession 오브젝트의 messageID array에 메세지 ID 값을 저장한다. returnunreadonly는 Boolean type의 파라미터로 읽지 않은 메세지 ID만 저장하도록 하는 옵션이다. mailGetMessages ( ) 가 리턴하는 값은 다음 중 하나이다.
n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!
n mailReturnUserAbort!
n mailReturnNoMessages!

? mailHandle ( )

MailSession 오브젝트의 핸들 값을 얻을 수 있다.

… mailLogoff ( )

현재 Mail Session을 종료 한다. mailLogOff ( ) 가 리턴하는 값은 다음 중 하나이다.
n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!

† mailLogon ( userid, password, logonoption )

새로운 Mail Session을 시작하고 사용자를 등록한다. userid와 password 값을 주지 않으면 입력하라는 창을 띄워서 사용자로부터 받아 들인다. logonoption은 로그 온 할 때의 옵션을 나타내는 것으로 다음 중 하나의 값을 갖는다.

n mailNewSession!
n mailDownLoad!
n mailNewSessionWithDownLoad!

logonoption 값을 주지 않으면 userid와 password를 입력하는 창이 뜨지 않는다. mailLogOn ( ) 함수가 리턴하는 값은 다음 중 하나이다.

n mailReturnSuccess!
n mailReturnFailure!
n mailLoginFailure!
n mailReturnInsufficientMemory!
n mailReturnTooManySessions!
n mailReturnUserAbort!

‡ mailReadMessage ( messageid, mailmessage, mailreadoption, mark )

ID가 messateid인 메세지를 읽을 때 사용 된다. 메세지 ID는 mailGetMessage ( ) 함수를 통해서 얻을 수 있다. mailreadoption은 다음 중 하나의 값을 갖는다.

n mailEntireMessage!
n mailEnvelopeOnly!
n mailBodyAsFile!
n mailSuppressAttach!

mark는 Boolean 파라미터로 해당 메세지를 읽었는지 안 읽었는지를 표시한다. mailReadMessage( )가 리턴하는 값은 다음 중 하나이다.

n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!

? mailRecipientDetails ( mailrecipient, allowupdates )

E-Mail 시스템의 수신자의 정보를 보여주는 창을 띄워 mailAddress ( ), mailResolveRecipient ( ), mailReadMessage ( ) 함수 등으로부터 리턴 된 수신자의 정보를 디스플레이 한다. allowupdates는 Boolean 파라미터로 detail 부분이 수정 될 수 있는지 여부를 나타낸다. mailRecipientDetails ( ) 함수가 리턴하는 값은 다음 중 하나이다.

n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!
n mailUnknownReturnRecipient!
n mailUnknownReturnUserAbort!
n mailResolveRecipient ( recipientname, allowupdates ) - 수신자의 이름을 얻을 수 있는 함수로 allowupdates는 수신자의 이름을 수정할 수 있는지 여부를 나타내는 Boolean 파라미터이다. mailResolveRecipient ( )는 다음 중 하나의 값을 리턴한다.

u mailReturnSuccess!
u mailReturnFailure!
u mailReturnInsufficientMemory!
u mailReturnUserAbort!

‰ mailSend ( mailmessage )

mailmessage 값을 주지 않으면 메세지를 입력 하도록Send Note 대화 창이 뜬다. mailSend ( ) 함수는 다음 중 하나의 값을 리턴한다.

n mailReturnSuccess!
n mailReturnFailure!
n mailReturnInsufficientMemory!
n mailReturnLogFailure!
n mailReturnUserAbort!
n mailReturnDiskFull!
n mailReturnTooManySessions!
n mailReturnTooManyFiles!
n mailReturnTooManuRecipients!
n mailReturnUnknownRecipient!
n mailReturnAttachmentNotFound!


MAPI를 사용하기 위한 enumerated data types :

?mailFileType - Attatchment의 타입으로 다음의 값을 갖는다.

n mailAttach!
n mailOLE!
n mailOLEStatic!

? mailLogonOption - Logon의 타입으로 다음의 값을 갖는다.

n mailNewSession!
n mailDownLoad!
n mailNewSessionWithDownLoad!

? mailReadOption - 메세지의 영역으로 다음의 값을 갖는다.

n mailBodyAsFile!
n mailEntireMessage!
n mailEnvelopeOnly!
n mailSuppressAttach!

? mailRecipientType - 수신자의 종류로 다음의 값을 갖는다.

n mailTo!
n mailCC!
n mailOriginator!
n mailBCC!

… mailReturnCode - mailReadMessage ( ) 함수로 부터 다음 중 하나의 값을 리턴한다.
n mailReturnAccessDenied!
n mailReturnAttachmentNotFound!
n mailReturnAttachmentOpenFailure!
n mailReturnAttachmentWriteFailure!
n mailReturnDiskFull!
n mailReturnFailure!
n mailReturnInsufficientMemory!
n mailReturnLoginFailure!
n mailReturnMessageInUse!
n mailReturnNoMessages!
n mailReturnSuccess!
n mailReturnTextTooLarge!
n mailReturnTooManyFiles!
n mailReturnTooManyRecipients!
n mailReturnTooManySessions!
n mailReturnUserAbort!

MAPI 인터페이스의 경우도 DDE 인터페이스의 예제와 마찬가지로 작성 할 수 있다. 단,cb_send의 스크립트를 다음과 같이 수정 한다.


Clicked Event ( cb_send )

/**************************************************************************
** MAPI를 사용해 메세지를 보낸다.
**************************************************************************/

mailSession mSes
mailReturnCode mRet
mailMessage mMsg
int iSendCnt, iAttachCnt


// Mail Session을 생성한다.
mSes = create mailsession

// 로그온 한다.
mRet = mSes.mailLogon ( mailNewSession! )

if mRet < > mailReturnSuccess! then
DisplayMsg ( "Mail Logon Error", "Unable to Log On to Mail" +
"System" )
Return
end if

mMsg.Subject = sle_subject.text
mMsg.NoteText = mle_note.text

for iSendCnt = 1 to lb_to.totalitems ( )
mMsg.Recipient[ iSendCntgt ].name = lb_to.item[ iSendCnt ]
sle_message.text = "Messages sent to : " + lb_to.item[ iSendCnt ]
next

for iSendCnt = 1 to lb_cc.totalitems ( )
mMsg.Recipient[ iSendCntgt ].name = lb_cc.item[ iSendCnt ]
sle_message.text = "Messages sent to : " + lb_cc.item[ iSendCnt ]
next

for i/AttachCnt = 1 to lb_attach.totalitems ( )
mMsg.AttachmentFile[ iattachCnt ]. FileName = &
lb_cc.tem[ iSendCnt ]
mMsg.AttachmentFile[ iattachCnt ]. FileType = mailAttach!
mMsg.AttachmentFile[ iattachCnt ]. Position = 1
next

mRet = mSes.mailSend ( mMsg )
if mRet < > mailReturnSuccess! then
DisplayMsg ( "Send Error", "Unable to send mail message" )
return
end if

mSes.mailLogoff ( )
destroy mSes

참고로 PowerBuilder의 MAPI 기능을 이용 해서 그림 2와 같은 메세지 관리 인터페이스를 쉽게 만들 수 있다.



그림 2


Open Event ( w_maintenance )

/**************************************************************************
** 이 스크립트의 내용은 먼저 Mail session을 만들고
** mailGetMessages ( ) 함수를 이용해 메세지 ID를 읽어 온다.
** 각각의 메세지에 대해서 정보를 읽어서 dw_msglist 데이터윈도우
** 에 입력한다. **************************************************************************/

int iMsgNbr, iIDcnt
long lCurRow
mailReturnCode mRet
mailMessage mMsg

// Mail session을 생성한다.
I_mSes = CREATE MailSession

// Session에 로그론 한다.
MRet = i_mSes.mailLogon ( mailNewSession! )

if mRet < > mailReturnSuccess! then
DisplayMsg ( "Mail Logon Error", "Unable to log on to Mail System" )
Return
end if

i_mSes.mailGetMessages ( TRUE )

// 메세지의 총 개수
iMsgNbr = Upperbound ( i_mSes.MessageID [ ] )

// 각각의 메세지에 대해서 정보를 읽어서 dw_msglist 데이터윈도우에
// SetItem을 한다. 메세지에 Attachment가 있으면 Attachment 칼럼을
// 1로 주어서 Attachment 비트맵이 나타나게 한다.

for iIDcnt = 1 to iMsgNbr
lCurRow = dw_msglist.insertrow ( 0 )
mRet = i_mSes.mailReadMessage ( i_mSes.MessageID [ iIDcnt ], &
mMsg, mailEnvelopeOnly!, True )
if not ( isNull ( mMsg.AttachmentFile [ 1 ].FileName ) ) then
dw_msglist.setItem ( lCurRow, "attachment", 1 )
end if

dw_msglist.setItem ( lCurRow, "messageID", &
i_mSes.MessageID [ iIDcnt ] )

dw_msglist.setItem ( lCurRow, "person", mMsg.Recipient [ 1 ]. Name )

dw_msglist.setItem ( lCurRow, "send_date", &
date ( mMsg.DateReceived ) )

dw_msglist.setItem ( lCurRow, "subject", mMsg.Subject )

next


Clicked Event ( cb_read )

/**************************************************************************
** 이 스크립트는 dw_msglist의 current row의 메세지를 디스플레이 한다.
**************************************************************************/

int iRowNum, iRetVal
string sMessageID
mailMessage mMsg
mailReturnCode mRet

iRowNum = dw_msglist.GetRow ( )

if iRowNum > 0 then
sMessageID = dw_msglist.GetItemString ( iRowNum, 'MessageID' )
mRet = i_mSes.MailReadMessage ( sMessageID, mMsg, &
mailEntireMessage~, True )

// 메세지를 디스플레이 할 수 있는 윈도우를 열어서 mMsg.NoteText의
// 값을 디스플레이 한다.
// ........
......
......
end if


Clicked Event ( cb_delete )

/**************************************************************************
** 이 스크립트는 dw_msglist의 current row의 메세지를 삭제 한다.
**************************************************************************/

string mMsgId
int iRowNum
mailReturnCode mRet

iRowNum = dw_msglist.GetRow ( )
if iRowNum > 0 then
sMsgID = dw_msglist.GetItemString ( iRowNum, "messageID" )
mRet = i_mSes.mailDeleteMessage ( sMsgID )
end if




l Lotus Notes PowerBuilder 라이브러리

Lotus Notes PowerBuilder 라이브러리에는 Lotus Notes와의 인터페이스를 위한 여러 가지 오브젝트가 제공 된다. 인터페이스는 Notes의 Simple messaging interface ( SMI )나 VIM을 사용해서 개발 할 수 있다. 오브젝트 라이브러리 뿐만 아니라 PLAN Toolkit( PowerBuilder Library application for Lotus Notes )으로 예제 어플리케이션과 유틸리티도 제공한다.
앞의 예제를 Lotus Notes PowerBuilder 라이브러리를 사용해서 만들기 위해서는 다음과 같이 하면 된다.


?PLAN Toolkit을 사용해서 데이터윈도우와 유저 오브젝트를 만든다.

? View Generator를 사용해서 메세지 리스트 오브젝트를 만든다.

? Form Generator를 사용해서 각각의 메세지를 읽을 수 있는 오브젝트를 생성한다.

? 생성한 오브젝트에 따라 데이터윈도우의 디자인을 적당히 수정한다.

… 윈도우에 두개의 유저 오브젝트를 추가한다. ( dw_list, dw_msg )

† 윈도우에 인스턴스 변수 iui_db_handle을 선언하고 Notes 데이터베이스의 Handle 값을 저장한다.

‡ 윈도우의 Open Event에 다음과 같은 스크립트를 작성한다.

if not f_database_open ( "C:\notes\mail\dletterm.nsf", &
iui_db_handle ) then return

dw_list.iui_db_handle = iui_db_handle
dw_msg.iui_db_handle = iui_db_handle

// ue_init와 ue_retrieve는 PLAN Toolkit에 의해서 만들어진 유저 오브젝트에
// 만든 사용자 이벤트이다.
// ue_init에서는 Notes API.DLL로 부터 PowerBuilder으로 데이터를 전송하기 위한
// 버퍼를 만든다.
// ue_retrieve에서는 Notes 데이터베이스로 부터 데이터를 데이터윈도우 버퍼에
// Retrieve 한다.
dw_1.TriggerEvent ( "ue_init" )
dw_1.TriggerEvent ( "ue_retrieve" )

f_database_open ( ) 은 PowerBuilder 글로벌 함수로 Lotus Notes PowerBuilder 라이브러리에 포함되어 있다. 이 함수는 Notes 데이터베이스를 열기 위한 Notes API 함수를 호출하며 코드는 다음과 같다.

// Function f_database_open
// Scope : Public
// Parameters : as_database_filename ( String/Value ) database file name
// aui_db_handle ( Uint/Ref ) database handle
// Returns : Boolean, True if successful, False if fails

int li_api_error

// 데이터베이스 핸들 값을 구한다.
li_api_error = PB_NSFDbOpen ( as_database_filename, aui_db_handle )

if ( li_api_error < > API_SUCCESS ) then
f_api_error ( li_api_error )
return False
end if

return True

? 윈도우의 Close Event에 다음의 코드를 추가 해서 데이터베이스 연결을 중단한다.

f_database_close ( iui_db_handle )

‰ cb_read의 Clicked Event에 다음의 코드를 추가해서 메세지를 읽어 온다.

long ll_row, ll_note_id

ll_row = this.GetClickedRow ( )
ll_note_id = this.GetItemNumber ( ll_row, "note_id" )

dw_msg.iul_note_id = ll_note_id
dw_msg.TriggerEvent ( "ue_init" )
dw_msg.TriggerEvent ( "ue_retrieve" )

? 마지막으로 cb_delete의 Clicked Event에 다음의 코드를 추가한다. 이 스크립트가 하는 것은 dw_msg의 현재의 Row를 삭제하도록 마크하고 데이터윈도우의 가장 왼쪽 칼럼에 쓰레기통 비트맵을 디스플레이 시킨다.

dw_list.TriggerEvent ( "ue_document_delete" )


l E-Mail API

앞에서 언급한 세 가지 방법 이외에 특정 E-Mail API를 직접 사용 해서 인터페이스를 만드는 경우도 있지만 훨씬 복잡하다. 결론적으로 말하자면 어떤 종류의 E-Mail 인터페이스를 선택할 것인가는 시스템에 따라, 또 어플리케이션에서 필요로 하는 기능에 따라 달라질 것이다

다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼