abap 发送邮件

*&---------------------------------------------------------------------*
*& Report  ZREP_CLS_029_SEND_EMAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZREP_CLS_029_SEND_EMAIL.
*data declaration related to sap link creation fro trip.
********************************************************
data: wda_naame type string,
      in_protocol type string,
      out_host type string,
      out_port type string,
      out_protocol type string,
      val         type string,
      g_url       type string.

*data declaration related to mail
*********************************************************
data: send_request type ref to cl_bcs,
      document    type ref to cl_document_bcs,
      send        type ref to if_sender_bcs,
      i_text      type  soli_tab,
      wa_text     type  soli,
      receiver    type ref to if_recipient_bcs,
      sent_to_all type os_boolean,
      sender      type adr6-smtp_addr,
      recipient     type adr6-smtp_addr,
      subject     type so_obj_des.
data:temp_addr type adr6-smtp_addr.

***************************************************************
* -generaating url for sap trasaction (sap gui for html)
***************************************************************
call method cl_http_server=>if_http_server~get_location
exporting
  protocol    = in_protocol
  server      = cl_wdr_task=>server
  importing
    host      = out_host
    port      = out_port
    out_protocol = out_protocol.

val = sy-mandt.
concatenate out_protocol '://' out_host ':' out_port '/sap/bc/gui/sap/its/ztrip' into g_url.
"/sap/bc/gui/sap/its/ patch for its service
"ztrip service name for tcode - trip,created thru sicf

call method cl_http_server=>append_field_url
exporting
  name    = 'sap-client'
  value   = val
  changing
    url   = g_url.

*****************************************************
*sending mail to outlook with sap link
*****************************************************

send_request = cl_bcs=>create_persistent( ).
concatenate 'Dear SDN,' '' into wa_text-line.
append wa_text-line to i_text.

concatenate 'Please find below link for Travel Request (TRIP ),' '' into wa_text-line.
append wa_text-line to i_text.

concatenate '<a href="' g_url '" > Link to Travel Request </a>' ' ' into wa_text-line.
append wa_text-line to i_text.

subject = 'SDN: Mail to Outlook with Saplink'.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_text
i_length = '18'
i_subject = subject ).

*add document to send request
call method send_request->set_document( document ).

*create internet address for the sender
send = cl_cam_address_bcs=>create_internet_address(
i_address_string = 'SDN@SAP.COM'
i_address_name   = 'SAP SDN').

*set the sender to send request instaance
call method send_request->set_sender
exporting
  i_sender = send.

temp_addr = 'wangxi@163.com'. "Receiving address
receiver = cl_cam_address_bcs=>create_internet_address( temp_addr ). "adding receipts

call method send_request->add_recipient
exporting
  i_recipient = receiver
  i_express   = 'X'.

send_request->set_send_immediately( 'X' ).

*sending the mail
call method send_request->send(
exporting
  i_with_error_screen = 'X'
  receiving
  result              = sent_to_all ).
if sent_to_all = 'X'.
  write :/ 'Mail has sent successfully'.
  endif.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值