标签:alt initial set span ram ring comm .com and
function zint_send_email.
*"----------------------------------------------------------------------
*"*"區域介面:
*" IMPORTING
*" VALUE(KTYPE) TYPE SO_OBJ_TP DEFAULT ‘RAW‘
*" VALUE(SUBJECT) TYPE SO_OBJ_DES
*" VALUE(TEXT) TYPE SOLI_TAB
*" VALUE(SENDER_ADDRESS) TYPE AD_SMTPADR
*" VALUE(SENDER_NAME) TYPE AD_SMTPADR OPTIONAL
*" VALUE(ATTACHMENTS) TYPE RMPS_T_POST_CONTENT OPTIONAL
*" VALUE(IMMEDIATELY) TYPE BOOLEAN OPTIONAL
*" EXPORTING
*" VALUE(E_RESULT) TYPE BOOLEAN
*" TABLES
*" T_RECIPIENT STRUCTURE UPS_YS_HR_CPERSON
*" RETURN STRUCTURE BAPIRET2
*"----------------------------------------------------------------------
data:send_request type ref to cl_bcs,
document type ref to cl_document_bcs,
sender_id type ref to if_sender_bcs,
fail type ref to cx_bcs,
recipient type ref to if_recipient_bcs.
data:w_return like bapiret2,
w_rename type ad_smtpadr,
w_attachment like line of attachments,
w_attachment_subject type sood-objdes.
*BREAK CP900.
refresh return.
clear e_result.
e_result = ‘X‘.
if ktype is initial.
w_return-type = ‘E‘.
w_return-message = ‘未指定文件類別代碼‘.
w_return-parameter = ‘KTYPE‘.
append w_return to return.
clear e_result.
endif.
if subject is initial.
w_return-type = ‘E‘.
w_return-message = ‘未指定郵件主題‘.
w_return-parameter = ‘SUBJECT‘.
append w_return to return.
clear e_result.
endif.
if text[] is initial.
w_return-type = ‘E‘.
w_return-message = ‘未指定郵件內容‘.
w_return-parameter = ‘TEXT‘.
append w_return to return.
clear e_result.
endif.
if sender_address is initial.
w_return-type = ‘E‘.
w_return-message = ‘未指定發送人郵件地址‘.
w_return-parameter = ‘SENDER_ADDRESS‘.
append w_return to return.
clear e_result.
endif.
if t_recipient[] is initial.
w_return-type = ‘E‘.
w_return-message = ‘未指定接收人郵件地址‘.
w_return-parameter = ‘RECIPIENT‘.
append w_return to return.
clear e_result.
endif.
clear w_return.
check e_result is not initial.
try.
* 第一步: 创建发送请求
send_request = cl_bcs=>create_persistent( ).
* 第二步: 创建整理发送内容
document = cl_document_bcs=>create_document(
i_type = ktype
i_text = text
i_subject = subject ).
* 增加附件內容
loop at attachments into w_attachment.
w_attachment_subject = w_attachment-subject.
document->add_attachment(
exporting
i_attachment_type = w_attachment-objtp
i_attachment_subject = w_attachment_subject
i_att_content_hex = w_attachment-cont_hex ).
endloop.
* 第三步: 添加邮件内容到发送请求
send_request->set_document( document ).
* 第四步:設置發送人出件地址
sender_id = cl_cam_address_bcs=>create_internet_address(
i_address_string = sender_address
i_address_name = sender_name ).
send_request->set_sender( sender_id ).
* 第五步: 接收者邮件地址转换
loop at t_recipient where cperson ne ‘99999999‘.
w_rename = t_recipient-emnam.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = t_recipient-e_mail
i_address_name = w_rename ).
send_request->add_recipient( recipient ).
endloop.
loop at t_recipient where cperson eq ‘99999999‘.
w_rename = t_recipient-emnam.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = t_recipient-e_mail
i_address_name = w_rename ).
* SEND_REQUEST->ADD_RECIPIENT( RECIPIENT ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_copy = ‘X‘.
endloop.
* 第六步,設置狀態屬性
send_request->set_status_attributes(
i_requested_status = ‘E‘
i_status_mail = ‘E‘ ).
send_request->set_send_immediately( immediately ).
* 第七步: 正式发送并提交作业
send_request->send( i_with_error_screen = ‘X‘ ).
commit work and wait.
catch cx_bcs into fail.
e_result = ‘‘.
w_return-type = ‘E‘.
w_return-message = fail->get_text( ).
append w_return to return.
clear w_return.
endtry.
endfunction.
标签:alt initial set span ram ring comm .com and
原文地址:http://www.cnblogs.com/rainysblog/p/6274439.html