用SO_DOCUMENT_SEND_API1發送郵件
代码语言:javascript复制PROGRAM: ztemail1.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SD'.
* SET TITLEBAR 'xxx'.
DATA: gd_doc_data LIKE sodocchgi1,
gd_sent_all(1) TYPE c,
gd_error TYPE sy-subrc,
it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: psubject1(30) TYPE c,
to_email1(40) TYPE c,
message1(43) TYPE c,
message2(43) TYPE c,
message3(43) TYPE c,
message4(43) TYPE c.
DATA: ok_code LIKE sy-ucomm.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CLEAR: it_message, it_message[].
REFRESH it_message.
APPEND message1 TO it_message.
APPEND message2 TO it_message.
APPEND message3 TO it_message.
APPEND message4 TO it_message.
gd_doc_data-doc_size = 1.
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject1.
gd_doc_data-sensitivty = 'F'.
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
CLEAR it_receivers.
REFRESH it_receivers.
it_receivers-receiver = to_email1.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
APPEND it_receivers.
CASE ok_code.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SEND'.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
sender_address = '123456789@qq.com'
sender_address_type = 'INT'
commit_work = 'X'
IMPORTING
sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
gd_error = sy-subrc.
LOOP AT it_receivers.
ENDLOOP.
WAIT UP TO 2 SECONDS.
IF gd_error EQ 0.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT