ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Abap SendMail Function

Abap SendMail Function

原创 Linux操作系统 作者:magiclhq 时间:2010-08-06 14:12:14 0 删除 编辑
      最近发现一个用Abap程式发送Mail 提醒信息的标准Function,可以在工作中引用,代码如下:
FUNCTION
 Z_E_RFC_WS_MAIL_SERVICE.
*"----------------------------------------------------------------------
*"Local Interface:
*"  IMPORTING
*"     VALUE(FROM) TYPE  STRING
*"     VALUE(TO) TYPE  STRING
*"     VALUE(MESSAGE) TYPE  STRING
*"     VALUE(SUBJECT) TYPE  STRING
*"  EXPORTING
*"     VALUE(RETURN) TYPE  BAPIRET2
*"-----------------------------------------------------
*-----------------------------------------------------*
* CLASS DEFINITIONS                                                    *
*-----------------------------------------------------*
  DATA: send_request       TYPE REF TO cl_bcs.
  DATA: document           TYPE REF TO cl_document_bcs.
  DATA: sender             TYPE REF TO if_sender_bcs.
  DATA: recipient          TYPE REF TO if_recipient_bcs.
  DATA: exception_info     TYPE REF TO if_os_exception_info,
        bcs_exception      TYPE REF TO cx_bcs.

*-----------------------------------------------------*
* INTERNAL TABLES                                                      *
*-----------------------------------------------------*
  DATA: l_mailtext TYPE soli_tab.

  TRY.
* Create persistent send request
      send_request = cl_bcs=>create_persistent( ).

* Move the Subject from string to BCS subject type
      DATA: l_subject TYPE so_obj_des.
      l_subject = subject.

* Move the message from string to internal table
      CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
        EXPORTING
          text      = message
        TABLES
          ftext_tab = l_mailtext.

* Create the Document
      document = cl_document_bcs=>create_document(
                          i_type    = 'RAW'
                          i_text    = l_mailtext
                          i_subject = l_subject ).

* Add document to send request
      CALL METHOD send_request->set_document( document ).

* Get sender object
      DATA: l_sender TYPE ad_smtpadr.
      l_sender = from.
      sender = cl_cam_address_bcs=>create_internet_address( l_sender ).

* Add sender
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.

* Get Recipient Object
      DATA: l_recipient TYPE ad_smtpadr.
      l_recipient = to.
      recipient = cl_cam_address_bcs=>create_internet_address( l_recipient

).

* Add recipient with its respective attributes to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient  = recipient.

* Set that you don't need a Return Status E-mail
      call method send_request->set_status_attributes
        exporting
          i_requested_status = 'E'
          i_status_mail      = 'E'.

* set send immediately flag
      send_request->set_send_immediately( 'X' ).

* Send document
      call method send_request->send( ).

      COMMIT WORK.

    CATCH cx_bcs INTO bcs_exception.
      data: l_message type string.
      l_message = bcs_exception->GET_TEXT( ).
      return-message = l_message.
  ENDTRY.


ENDFUNCTION.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9381143/viewspace-670427/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-01-02

  • 博文量
    33
  • 访问量
    67653