SAP中发外部Mail的方式

REPORT ZZXTEST111.

datal_send_request type ref to cl_bcs,         " Send request
      l_body      type bcsy_text,                " Mail body
      l_success   type bcsy_text,                " Atchmnt for success
      l_error     type bcsy_text,                " Atchmnt for error
      wa_text     type soli,                     " Work area for attach
      l_document  type ref to cl_document_bcs,   " Mail body
      l_sender    type ref to if_sender_bcs,     " Sender address
      l_recipient type ref to if_recipient_bcs,  " Recipient
      l_size      type sood-objlen,              " Size of Attachment
      l_lines     type i,                        " Lines count
      l_email     type ad_smtpadr,               " Email ID
      l_extension type soodk-objtp value 'RAW'.  " TXT format
* Prepare mail bidy
append 'Send multiple file as attachment of a Email.'  to l_body.
append space to l_body.
* Preparing contents of attachment with Change Log
* Header line
wa_text-line+0   'First column'.
wa_text-line+20  'Second column'.
wa_text-line+40  'Third column'.
wa_text-line+60  'Fourth column'.
wa_text-line+80  'Fifth column'.
wa_text-line+100 'Sixth column'.
wa_text-line+120 'Seventh column'.
wa_text-line+140 'Eighth column'.
append wa_text to l_success.
append wa_text to l_error.
clear wa_text.
* Populate the data part
wa_text-line+0   '111111111'.
wa_text-line+20  '222222222'.
wa_text-line+40  '333333333'.
wa_text-line+60  '333333333'.
wa_text-line+80  '444444444'.
wa_text-line+100 '555555555'.
wa_text-line+120 '666666666'.
wa_text-line+140 '777777777'.
append wa_text to l_success.
clear wa_text.
wa_text-line+0   'aaaaaaaaa'.
wa_text-line+20  'bbbbbbbbb'.
wa_text-line+40  'ccccccccc'.
wa_text-line+60  'ddddddddd'.
wa_text-line+80  'eeeeeeeee'.
wa_text-line+100 'fffffffff'.
wa_text-line+120 'ggggggggg'.
wa_text-line+140 'hhhhhhhhh'.
append wa_text to l_error.
clear wa_text.
* Creates persistent send request
l_send_request cl_bcs=>create_persistent).
* Craete document for mail body
l_document cl_document_bcs=>create_document(
             i_type    'RAW'
             i_text    l_body  " Mail body
             i_subject 'Mail send as attachment' ).
* Attachment for success records
l_lines linesl_success ).
l_size l_lines * 255.
* Add attchment
call method l_document->add_attachment
  exporting
    i_attachment_type    l_extension
    i_attachment_subject 'Success'
    i_attachment_size    l_size
    i_att_content_text   l_success" Attachment for success record
* Attachment for error records
l_lines linesl_error ).
l_size l_lines * 255.
* Add attchment
call method l_document->add_attachment
  exporting
    i_attachment_type    l_extension
    i_attachment_subject 'Error'
    i_attachment_size    l_size
    i_att_content_text   l_error" Attachment for error record
* Add the document to send request
call method l_send_request->set_documentl_document ).
* Sender addess
l_sender cl_sapuser_bcs=>createsy-uname ).
call method l_send_request->set_sender
  exporting
    i_sender l_sender.
* Recipient address
l_email = 'XXXXXXXX@yahoo.com'.
l_recipient cl_cam_address_bcs=>create_internet_addressl_email ).
* Add recipient address to send request
call method l_send_request->add_recipient
  exporting
    i_recipient  l_recipient
    i_express    'X'
    i_copy       ' '
    i_blind_copy ' '
    i_no_forward ' '.
*l_email = 'myname@gmail.com'.
*l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
** Add recipient address to send request
*call method l_send_request->add_recipient
*  exporting
*    i_recipient  = l_recipient
*    i_express    = 'X'
*    i_copy       = ' '
*    i_blind_copy = ' '
*    i_no_forward = ' '.
* E-Mail is placed into queue for sending. In case of very important alerts
* use the following parameter to initiate an 'immediate sending'; but notice that
* this will trigger a dedicated send process for every single message - which is
* very costly for system performance
* l_send_request->set_send_immediately( 'X' ). "uncomment for immediate sending
* Send mail
call method l_send_request->send).
commit work.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值