生活随笔
收集整理的這篇文章主要介紹了
SAP-ABAP程序发送邮件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 變量定義:
類:?CL_BCS?– Business Communication Service, 發送郵件主要用到的功能類, 包括創建發送請求, 添加發送內容,添加發送地址, 到最終的發送指令發出.
send_request type ref to cl_bcs.
類:?CL_DOCUMENT_BCS,?用來放置發送的內容.
document type ref to cl_document_bcs.
類:?CX_BCS,?不用多說,這是個異常類, 用于捕捉發送郵件過程中出現的異常.
fail type ref to cx_bcs.
接口:?IF_RECIPIENT_BCS, 用來做郵件地址的存儲轉換.
recipient type ref to if_recipient_bcs.
2.?? 編程步驟:
2.1. 創建發送請求:
send_request = cl_bcs=>create_persistent( ).
2.2. 創建整理發送內容
document = cl_document_bcs=>create_document(
i_type?????? = ‘RAW’
i_text?????? = 郵件內容
i_subject = 郵件抬頭 ).
document->add_attachment: 這個可以添加些附件
2.3. 添加郵件內容到發送請求
send_request->set_document( document ).
2.4. 郵件地址轉換
recipient = cl_cam_address_bcs=>create_internet_address( 郵件地址 )
2.5. 添加郵件地址到發送請求
send_request->add_recipient( recipient )
2.6. 正式發送并且提交作業
send_request->send( i_with_error_screen = ‘X’ )
commit work and wait.
3. 具體實例
[java] view plaincopy
*&---------------------------------------------------------------------*??REPORT??ZBOBO_003.??*?前提之變量定義????DATA:??????send_request?TYPE?REF?TO?cl_bcs,??????document?TYPE?REF?TO?cl_document_bcs,??????fail?TYPE?REF?TO?cx_bcs,??????recipient?TYPE?REF?TO?if_recipient_bcs.????DATA:??????ls?TYPE?STRING,??????mailto?????????TYPE?ad_smtpadr,??????main_text??????TYPE?bcsy_text,??TITLE??????????TYPE?so_obj_des.????ls?=?'該郵件用于測試演示程序'.??APPEND?ls?TO?main_text.??TITLE?=?'翱翔云天測試郵件'.????mailto?=?'CHUNBO.XU@ALCATEL-SBELL.COM.CN'.????TRY.??*???第一步:?創建發送請求??????send_request?=?cl_bcs=>create_persistent(?).??*???第二步:?創建整理發送內容??????document?=?cl_document_bcs=>create_document(????????????i_type????=?'RAW'????????????i_text????=?main_text????????????i_subject?=?TITLE?).??*???第三步:?添加郵件內容到發送請求??????send_request->set_document(?document?).??*???第四步:?郵件地址轉換??????recipient?=?cl_cam_address_bcs=>create_internet_address?(?mailto?).??*???第五步:?添加郵件地址到發送請求??????send_request->add_recipient(?recipient?).??*???第六步:?正式發送并提交作業??????send_request->send(?i_with_error_screen?=?'X'?).??COMMIT?WORK?AND?WAIT.??CATCH?cx_bcs?INTO?fail.??*????MESSAGE?ixxx(xx)?WITH?fail->error_type.????ENDTRY.?
總結
以上是生活随笔為你收集整理的SAP-ABAP程序发送邮件的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。