SAP-ABAP程序发送邮件

来源:互联网 发布:桃源网络硬盘5.8 破解 编辑:程序博客网 时间:2024/04/26 03:34

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. 具体实例

*&---------------------------------------------------------------------**& Report  ZBOBO_003*&*&---------------------------------------------------------------------**& 用于如何写abap程序发送邮件的DEMO程序*& 翱翔云天原创*& 翱翔云天六步法发送邮件*&---------------------------------------------------------------------*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.4. 效果查看:


原创粉丝点击