sap abap发送email

 例子1.

http://blog.chinaunix.net/u1/44070/showart_1069899.html

例子2.

http://jgtang82.iteye.com/blog/186430

demo 3

http://www.sapdev.co.uk/reporting/email/email_sapmail.htm

demo4

http://blog.chinaunix.net/u1/40527/showart_453984.html

 

 

  我在程序中使用的send email 的 function

 

 call function 'SO_NEW_DOCUMENT_SEND_API1'
    exporting
      document_data              = ls_docdata
      document_type              = 'RAW'
      put_in_outbox              = 'X'
      commit_work                = 'X'
    tables
      object_content             = lt_objcont
      receivers                  = lt_reclist
    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.

 

 

 

 

2.15 例子  为了是在email中保持格式   使用html来显示

    由于wa_html-line  一行只能255字符 

  我在sap 界面设置中开启了 70个字符换行    造成wa_html-line一遍遍添加到html表中

最后用于传输

 

*&---------------------------------------------------------------------*
*& Report  ZTEST_EMAIL1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_EMAIL1.

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,
      html                  TYPE STANDARD TABLE OF solisti1,
*      wa_html           TYPE w3html,
      wa_html           TYPE solisti1,
      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.



lv_title = 'This is the title'.

*wa_html-line = '<html><body>'.
*APPEND wa_html TO html.
wa_html-line = '<table border=14 borderColor=#cccccc width=100%>'.
APPEND wa_html to html.
CLEAR wa_html.
wa_html-line = '<tr><td>&nbsp;序号</td>' .
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;员工号</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;员工姓名</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;工具编码</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;序列号</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;工具描述</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;规格型号</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;数量</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;工厂</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;仓库</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;应归还日期</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;提醒次数</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;部门</td>'.
APPEND wa_html to html.
wa_html-line = '<td>&nbsp;所属专业</td>'.
APPEND wa_html to html.
wa_html-line = '</tr></table>'.
append wa_html to html.

*wa_html-line = '</body></html>'.
*APPEND wa_html TO html.

TRY.
    CLEAR send_request.
    send_request = cl_bcs=>create_persistent( ).

    CLEAR document .
    document =  cl_document_bcs=>create_document(
                    i_type =    'HTM'
                    i_text =     html
                    i_length =  conlengths
                    i_subject = lv_title ).


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



*   Construct sender and receiver
    CLEAR: sender_id , recipient .
    sender_id = cl_cam_address_bcs=>create_internet_address(
'*****@****.com.cn' ).
    recipient = cl_cam_address_bcs=>create_internet_address(
'*****@*****.com.cn' ).

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



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



*   Set E-mail sending options
    CALL METHOD send_request->set_status_attributes
      EXPORTING
        i_requested_status = 'E'
        i_status_mail      = 'E'.
    CALL METHOD send_request->set_send_immediately( 'X' ).

*   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.

  CATCH cx_bcs INTO bcs_exception.
    bcs_message = bcs_exception->get_text( ).
    MESSAGE bcs_exception TYPE 'E'.
    EXIT.
ENDTRY.


******************************************
* get sender email address.
*
* CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
*    EXPORTING
*        USER_NAME              = 'fuwuqi'
**       READ_DB_DIRECTLY       = ' '
**    IMPORTING
**        USER_ADDRESS           = FS_ADDR
**        USER_USR03             = FS_USR03
*    EXCEPTIONS
*        USER_ADDRESS_NOT_FOUND = 1
*        OTHERS                 = 2.

 

2011.04.22 PS:在运行functions后面加上这句 可以立即处理邮件  是邮件快速发送 减少处理的延时

          TCODE:SCOT  可以查看系统是否挤压邮件

if sy-subrc = 0.
    commit work and wait.
    "send immediatly
    submit rsconn01 with mode = 'INT' and return.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值