abap,oo发送邮件

  • 格式:txt
  • 大小:3.98 KB
  • 文档页数:2
endif.
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
endloop.
endif.
try.
** Send email
*" VALUE(RECIPIENT_UID) TYPE SYUNAME OPTIONAL
*" VALUE(SENDER_MAIL) TYPE ADR6-SMTP_ADDR OPTIONAL
*" VALUE(RECIPIENT_MAIL) TYPE ADR6-SMTP_ADDR OPTIONAL
endif.
lo_send_request->add_recipient(
EXPORTING
i_recip#39;X' ).
else.
loop at recipients into ls_recipient.
if ls_recipient-iusrid is not initial.
lv_recipient_uid = ls_recipient-iusrid.
lo_recipient = cl_sapuser_bcs=>create( lv_recipient_uid ).
endtry.
* Set recipients
if recipients[] is initial.
if recipient_mail is not initial.
lo_recipient = cl_cam_address_bcs=>create_internet_address( recipient_mail ).
catch cx_send_req_bcs.
result = ''.
endtry.
ENDFUNCTION.
elseif recipient_uid is not initial.
lo_recipient = cl_sapuser_bcs=>create( recipient_uid ).
else.
lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
lo_send_request->set_document( lo_document ).
try.
if sender_mail is not initial.
lo_sender = cl_cam_address_bcs=>create_internet_address( sender_mail ).
*" EXPORTING
*" VALUE(RESULT) TYPE BOOLEAN
*" TABLES
*" RECIPIENTS STRUCTURE UIYS_IUSR OPTIONAL
*"----------------------------------------------------------------------
* DATA:
* lt_message_body TYPE bcsy_text VALUE IS INITIAL,
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL,
attachment_subject type SO_OBJ_DES.
DATA: lv_recipient_uid TYPE uname,
lv_recipient_mail TYPE adr6-smtp_addr.
*Prepare Mail Object
CLASS cl_bcs DEFINITION LOAD.
lo_send_request = cl_bcs=>create_persistent( ).
*" VALUE(MESSAGE_BODY) TYPE BCSY_TEXT
*" VALUE(ATTACHMENTS) TYPE RMPS_T_POST_CONTENT OPTIONAL
*" VALUE(SENDER_UID) TYPE SYUNAME OPTIONAL
elseif ls_recipient-email is not initial.
lv_recipient_mail = ls_recipient-email .
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_recipient_mail ).
DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
data: ls_recipient like line of recipients,
ls_attachment like line of attachments.
*Data Declaration
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
l_send type ADR6-SMTP_ADDR ,
l_rec type ADR6-SMTP_ADDR .
elseif sender_uid is not initial.
lo_sender = cl_sapuser_bcs=>create( sender_uid ).
else.
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
FUNCTION ZNPI_SEND_MAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(SUBJECT) TYPE SO_OBJ_DES
Data : ITAB TYPE TABLE OF SVAL,
LS_ITAB TYPE SVAL,
i_RETURN.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = ls_attachment-OBJTP
i_attachment_subject = attachment_subject
i_text = message_body
i_subject = subject ).
*Send attachment
loop at attachments into ls_attachment.
attachment_subject = ls_attachment-subject.
i_att_content_hex = ls_attachment-CONT_HEX ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
endloop.
* Pass the document to send request
endif.
* Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
catch CX_ADDRESS_BCS.
return.
* Message body and subject
data: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = result ).
COMMIT WORK.
wait up to 1 seconds.

下载文档原格式

  / 2