邮件发送范例
REPORT Y001.
*类: CL_BCS 发送邮件主要用到的功能类, 包括创建发送请求, 添加发送内容,添加发送地址, 到最终的发送指令发出.
*类: CL_DOCUMENT_BCS, 用来放置发送的内容.
*类: CX_BCS, 不用多说,这是个异常类, 用于捕捉发送邮件过程中出现的异常.
*接口: IF_RECIPIENT_BCS, 用来做邮件地址的存储转换.
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 = 'sanlly333@gmail.com'.
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.
ENDTRY.