E-Mail versenden
Beispielcoding: E-Mail direkt aus dem SAP mit Anhang versenden: (kopieren erlaubt aber auf eigene Gefahr :-))
Es wird der Funktionsbaustein SO_NEW_DOCUMENT_ATT_SEND_API1 verwendet.
Wird kein Anhang benötigt so kann man auch den Fubau SO_NEW_DOCUMENT_SEND_API1 verwenden.
*
* Coded by Thorsten Neubüser - www.4ap.de
*
*&---------------------------------------------------------------------*
*& Report Z_TN_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_tn_test.
* Testprogramm für Fubau-Mailversand mit Attachment
* SO_NEW_DOCUMENT_ATT_SEND_API1
DATA: lt_objpack TYPE TABLE OF sopcklsti1,
ls_objpack TYPE sopcklsti1,
lt_objhead TYPE TABLE OF solisti1,
ls_objhead TYPE solisti1,
lt_objbin TYPE TABLE OF solisti1,
ls_objbin TYPE solisti1,
lt_objtxt TYPE TABLE OF solisti1,
ls_objtxt TYPE solisti1,
lt_reclist TYPE TABLE OF somlreci1,
ls_reclist TYPE somlreci1,
ls_document_data TYPE sodocchgi1,
lv_tab_lines TYPE sy-tabix.
PARAMETERS:
p_send TYPE xflag.
* Erstellen des zu versendenden Dokuments
ls_document_data-obj_name = 'ANGEBOT'.
ls_document_data-obj_descr = 'Versteigerung eines nachgemachten Picassos'(t01).
ls_objtxt = 'Mindestgebot : 25.000 €'(t02).
APPEND ls_objtxt to lt_objtxt.
ls_objtxt = 'Eine Abbildung des zur Versteigerung stehenden Bildes'(t03).
APPEND ls_objtxt to lt_objtxt.
ls_objtxt = 'wurde als Anlage beigefügt.'(t04).
APPEND ls_objtxt to lt_objtxt.
DESCRIBE TABLE lt_objtxt LINES lv_tab_lines.
READ TABLE lt_objtxt INTO ls_objtxt INDEX lv_tab_lines.
ls_document_data-doc_size = ( lv_tab_lines - 1 ) * 255 + STRLEN( ls_objtxt ).
* Erstellen des Eintrags zum komprimierten Dokument
CLEAR ls_objpack.
ls_objpack-transf_bin = ''.
ls_objpack-head_start = 1.
ls_objpack-head_num = 0.
ls_objpack-body_start = 1.
ls_objpack-body_num = lv_tab_lines.
ls_objpack-doc_type = 'RAW'.
APPEND ls_objpack to lt_objpack.
* Erstellen der Anlage für das Dokument
* (Man stelle sich die Daten in gt_objbin im BMP-Format angegeben vor)
ls_objbin = ' \O/ '. APPEND ls_objbin to lt_objbin.
ls_objbin = ' '. APPEND ls_objbin to lt_objbin.
ls_objbin = ' / \ '. APPEND ls_objbin to lt_objbin.
DESCRIBE TABLE lt_objbin LINES lv_tab_lines.
ls_objhead = 'picasso.bmp'(t05). APPEND ls_objhead to lt_objhead.
* Erstellen des Eintrags zur komprimierten Anlage
clear: ls_objpack.
ls_objpack-transf_bin = 'X'.
ls_objpack-head_start = 1.
ls_objpack-head_num = 1.
ls_objpack-body_start = 1.
ls_objpack-body_num = lv_tab_lines.
ls_objpack-doc_type = 'BMP'.
ls_objpack-obj_name = 'ANLAGE'(t06).
ls_objpack-obj_descr = 'Abbildung Objekt 138'(t07).
ls_objpack-doc_size = lv_tab_lines * 255.
APPEND ls_objpack to lt_objpack.
* Füllen der Empfängerliste
clear ls_reclist.
ls_reclist-receiver = 'test@test.de'(t08).
ls_reclist-rec_type = 'U'.
APPEND ls_reclist to lt_reclist.
* ls_reclist-RECEIVER = 'DLI-NEUREICH'.
* ls_reclist-REC_TYPE = 'P'.
* APPEND ls_reclist to lt_reclist.
* Versenden des Dokuments
IF p_send = 'X'.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_document_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
receivers = lt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
CASE sy-subrc.
WHEN 0.
WRITE: / 'Ergebnis des Sendevorgangs:'(t09).
LOOP AT lt_reclist INTO ls_reclist.
WRITE: / ls_reclist-receiver(48), ':'.
IF ls_reclist-retrn_code = 0.
WRITE 'erfolgreich versendet'(t10).
ELSE.
WRITE 'nicht versendet'(t11).
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'Keine Berechtigung, an die angegebene Anzahl Empfänger zu senden !'(e01).
WHEN 2.
WRITE: / 'Dokument konnte an keinen Empfänger gesendet werden!'(e02).
WHEN 4.
WRITE: / 'Keine Berechtigung zum Senden !'(e03).
WHEN OTHERS.
WRITE: / 'Fehler beim Senden aufgetreten !'(e04).
ENDCASE.
ENDIF. " p_send = 'X'
***************
* *
* T T *
* N *
* *
* `---´ *
* *
***************