Chinaunix首页 | 论坛 | 博客
  • 博客访问: 146267
  • 博文数量: 54
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 508
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-18 09:25
个人简介

好男人就是我,我就是你兵哥

文章分类

全部博文(54)

我的朋友

分类: IT职场

2014-10-16 14:50:44

FUNCTION ZNP_SEND_EMAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IV_SENDER) TYPE  AD_SMTPADR
*"     REFERENCE(IT_RECIPIENT) TYPE  ZNP_RECIPIENT_TAB *表类型,里面只有一个行类型AD_SMTPADR
*"     REFERENCE(IV_TITLE) TYPE  SO_OBJ_DES
*"     REFERENCE(IT_CONTENT) TYPE  SOLI_TAB
*"  EXPORTING
*"     REFERENCE(SENT_TO_ALL) TYPE  OS_BOOLEAN
*"----------------------------------------------------------------------
 DATA: lv_title          TYPE so_obj_des,
        send_request      TYPE REF TO cl_bcs,
        document          TYPE REF TO cl_document_bcs,
        conlengths        TYPE so_obj_len,
        html              TYPE STANDARD TABLE OF w3html,
        wa_html           TYPE w3html,
        sender_id         TYPE REF TO if_sender_bcs,
        recipient         TYPE REF TO if_recipient_bcs,
        "sent_to_all       TYPE os_boolean,
        bcs_exception     TYPE REF TO cx_bcs,
        bcs_message       TYPE string.

***输入参数检查
  IF iv_sender IS INITIAL.
    EXIT.
  ENDIF.
  IF it_recipient IS INITIAL.
    EXIT.
  ENDIF.
  IF iv_title IS INITIAL.
    EXIT.
  ENDIF.
  CLEAR send_request.
  try.
    send_request = cl_bcs=>create_persistent( ).
    catch cx_root.
*      RAISE could_not_create.
*      raise exception type cx_send_req_bcs


  endtry.
*  send_request = cl_bcs=>create_persistent( ).

  CLEAR document .
TRY.
  document =  cl_document_bcs=>create_document(
                  i_type    =  'HTM'
*                  i_type    =  'RAW'
                  i_text    =  it_content
                  i_length  =  conlengths
                  i_subject =  iv_title ).
ENDTRY.
*   Add document to send request
  CALL METHOD send_request->set_document( document ).

*   Construct sender and receiver
  IF NOT iv_sender IS INITIAL.
    CLEAR: sender_id , recipient .
    sender_id = cl_cam_address_bcs=>create_internet_address( iv_sender ).
*   Set sender
    CALL METHOD send_request->set_sender
      EXPORTING
        i_sender = sender_id.
  ENDIF.

  DATA ls_recipient LIKE LINE OF it_recipient.
  DATA lv_has_recipient TYPE char1.
  lv_has_recipient = ''.
  LOOP AT it_recipient INTO ls_recipient.
    IF ls_recipient IS INITIAL.
      CONTINUE.
    ENDIF.
    CLEAR recipient.
    recipient = cl_cam_address_bcs=>create_internet_address( ls_recipient ).
*   Add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
      EXPORTING
        i_recipient = recipient
        i_express   = 'X'.
    lv_has_recipient = 'X'.
  ENDLOOP.
  IF lv_has_recipient = ''.
    EXIT.
  ENDIF.

*   Set E-mail sending options
  CALL METHOD send_request->set_status_attributes
    EXPORTING
      i_requested_status = 'E'
      i_status_mail      = 'E'.
TRY.
  CALL METHOD send_request->set_send_immediately( 'X' ).
ENDTRY.
*   Send document
  CALL METHOD send_request->send(
   EXPORTING
     i_with_error_screen = 'X'
   RECEIVING
     result = sent_to_all ).

  IF sent_to_all = 'X'.
    MESSAGE 'Mail sent successfully ' TYPE 'S'.
  ENDIF.
  COMMIT WORK.


ENDFUNCTION.

阅读(1810) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~