ABAP 发送邮件(正文部分需要表格&图片)
上面截图是最后开发交付截图,左上角是公司LOGO,正文部分是表格。
现在开始开发邮件发送部分
1.上传图片
选择MIME知识库,选中SAP-PUBLIC 导入MIME对象
选择图片上传即可
2.写程序(程序部分只有发送邮件关键内容部分)
DATA:ls_data TYPE ty_data,
lt_data TYPE TABLE OF ty_data.
DATA:lt_body TYPE bcsy_text,
ls_body TYPE soli.
DATA:lv_subject TYPE sood-objdes,
lv_title TYPE sood-objdes.
DATA lt_text TYPE bcsy_text.
DATA sent_to_all TYPE os_boolean.
DATA send_request TYPE REF TO cl_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA: lo_sender TYPE REF TO if_sender_bcs.
DATA document TYPE REF TO cl_document_bcs.
DATA:lv_zcsr TYPE ad_smtpadr.
DATA bcs_exception TYPE REF TO cx_bcs.
*&---------------------------------------------------------------------*
*& GET LOGO DATA DEFINE
*&---------------------------------------------------------------------*
DATA : lt_pick_data TYPE TABLE OF w3mime,
lt_query TYPE TABLE OF w3query,
ls_query TYPE w3query,
lt_html TYPE TABLE OF w3html,
lv_return_code TYPE w3param-ret_code,
lv_content_type TYPE w3param-cont_type,
lv_content_length TYPE w3param-cont_len,
lv_url(255) TYPE c,
lv_pic_size TYPE i,
lv_text_img TYPE so_text255.
DATA: o_mr_api TYPE REF TO if_mr_api.
DATA is_folder TYPE boole_d.
DATA lv_content TYPE xstring.
DATA lv_loio TYPE skwf_io.
DATA : lo_mime_helper TYPE REF TO cl_gbt_multirelated_service.
DATA:l_obj_len TYPE i,
lv_graphic_length TYPE i,
l_offset TYPE i,
l_length TYPE i,
l_diff TYPE i.
DATA:lr_xstr TYPE string,
ls_solix TYPE solix,
lt_solix TYPE solix_tab.
DATA b64data TYPE string.
*&---------------------------------------------------------------------*
*& mail Content
*&---------------------------------------------------------------------*
*----- Email Subject -----------*
lv_title = '<b>采购质量不合格通知:</b>'.
*----- Email Company LOGO -----------*
IF o_mr_api IS INITIAL.
o_mr_api = cl_mime_repository_api=>if_mr_api~get_api( ).
ENDIF.
*----add logo picture-------*
CALL METHOD o_mr_api->get
EXPORTING
i_url = '/SAP/PUBLIC/logo.bmp'
IMPORTING
e_is_folder = is_folder
e_content = lv_content
e_loio = lv_loio
EXCEPTIONS
parameter_missing = 1
error_occured = 2
not_found = 3
permission_failure = 4
OTHERS = 5.
CALL FUNCTION 'SSFC_BASE64_ENCODE'
EXPORTING
bindata = lv_content
IMPORTING
b64data = b64data.
IF sy-subrc <> 0.
ENDIF.
l_obj_len = strlen( b64data ).
lv_graphic_length = strlen( b64data ).
lr_xstr = b64data.
l_offset = 0.
l_length = 255.
CLEAR : ls_body.
ls_body-line = '<img src="data:image/bmp;base64,'.
APPEND ls_body TO lt_body.
CLEAR : ls_body.
WHILE l_offset < lv_graphic_length .
l_diff = lv_graphic_length - l_offset.
IF l_diff > l_length.
ls_body-line = lr_xstr+l_offset(l_length).
ELSE.
ls_body-line = lr_xstr+l_offset(l_diff).
ENDIF.
APPEND ls_body TO lt_body.
ADD l_length TO l_offset.
ENDWHILE.
CLEAR : ls_body.
ls_body-line = '" align="left" />'.
APPEND ls_body TO lt_body.
CLEAR : ls_body.
ls_body-line = '</br>'.
APPEND ls_body TO lt_body.
*----- Email Attachment name -----------*
*----Body of the email here--------*
ls_body-line = '<b>采购质量不合格通知:</b>'.
APPEND ls_body TO lt_body. "Body of the email
CLEAR : ls_body.
APPEND ls_body TO lt_body..
CLEAR : ls_body.
*----add form-------*
ls_body-line = '<table width="75%" border="1" cellspacing="0">'.
APPEND ls_body TO lt_body.
CLEAR : ls_body.
ls_body-line = '<tr><td>通知单号</td><td>检验批次号</td><td>物料号</td><td>物料描述</td><td>入库批号</td><td>检验项目</td><td>检验结果</td><td>检验结论</td></tr>'.
APPEND ls_body TO lt_body.
LOOP AT lt_data INTO ls_data.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = ls_data-matnr
IMPORTING
output = ls_data-matnr.
CLEAR : ls_body.
ls_body-line = '<tr><td>' && ls_data-qmnum && '</td>' &&
'<td>' && ls_data-prueflos && '</td>' &&
'<td>' && ls_data-matnr && '</td>' &&
'<td>' && ls_data-maktx && '</td>' &&
'<td>' && ls_data-charg && '</td>' &&
'<td>' && ls_data-zqmxm && '</td>' &&
'<td>' && ls_data-zqmjg && '</td>' &&
'<td>' && ls_data-zqmjl && '</td></tr>'.
APPEND ls_body