Hallo Holger,
Sorry dauerte etwas länger.
Hier das Script:
report z_tm_mail .
data: itcpo like itcpo,
tab_lines like sy-tabix,
zahl(2) type c,
start type i,
end type i.
types: typ_recceivers like somlreci1,
typ_document_data like sodocchgi1,
typ_object_content like solisti1,
typ_object_parb like soparbi1,
typ_packlist like sopcklsti1,
typ_content_bin like solisti1,
typ_content_txt like solisti1.
data: it_recceivers type table of typ_recceivers,
wa_recceivers like line of it_recceivers,
wa_document_data type typ_document_data,
it_object_content type table of typ_object_content,
wa_object_content like line of it_object_content,
it_object_header type table of typ_object_content,
wa_object_header like line of it_object_header,
it_object_parb type table of typ_object_parb,
wa_object_parb like line of it_object_parb,
it_packlist type table of typ_packlist,
wa_packlist like line of it_packlist,
it_content_bin type table of typ_content_bin,
wa_content_bin like line of it_content_bin,
it_content_txt type table of typ_content_txt,
wa_content_txt like line of it_content_txt.
perform send_form_via_email.
************************************************************************
* FORM SEND_FORM_VIA_EMAIL *
************************************************************************
form send_form_via_email.
clear: wa_document_data, it_content_txt, wa_content_bin, wa_packlist,
wa_object_header, wa_recceivers.
refresh: it_content_txt, it_content_bin, it_packlist,
it_object_header, it_recceivers.
* Creation of the document to be sent File Name
* wa_document_data-obj_name = 'TEST1.txt'.
* Mail Subject/ Betrefftext der im Mailbetreff erscheinen soll
wa_document_data-obj_descr = 'Betreff'.
* Mail Contents
* Mail Body, Text in der Mail, nicht der im Anhang.
* Es können auch HTML Formatierungen mit eingebracht werden.
wa_content_txt-line = 'Diese Mail wurde automatisch erstellt<BR>'.
append wa_content_txt to it_content_txt.
concatenate 'Bei Fragen wenden Sie sich an ' into wa_content_txt-line.
append wa_content_txt to it_content_txt.
wa_content_txt-line = '<BR>'.
append wa_content_txt to it_content_txt.
* Prepare Packing List
perform prepare_packing_list.
* Set recipient - email address here!!!
* Empfängermailadressen eintragen
* U für extern, B für intern
* Für interen User die Personalnummer eintragen.
wa_recceivers-receiver = 'empfä
nger@minden.de'.
wa_recceivers-rec_type = 'U'. " B = intern ; U = extern
* Alle die Mailadressen die diese Mail als Blindcopy erhalten sollen,
* müssen angefügt werden.
* wa_recceivers-blind_copy = 'X'.
* No Forward gilt nur für die SAP User.
* wa_recceivers-no_forward = 'X'.
append wa_recceivers to it_recceivers.
* Sending the document
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = wa_document_data
* Übergibt Dokument in die Ausgangsbox des Senders.
put_in_outbox = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
tables
packing_list = it_packlist
object_header = it_object_header
contents_bin = it_content_bin
contents_txt = it_content_txt
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = it_recceivers
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
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform.
************************************************************************
* Form PREPARE_PACKING_LIST
************************************************************************
form prepare_packing_list.
clear: wa_packlist, it_content_bin, wa_object_header.
refresh: it_packlist, it_content_bin, it_object_header.
describe table it_content_txt lines tab_lines.
read table it_content_txt index tab_lines into wa_content_txt.
* Größe des Maildokumentes bestimmen.
wa_document_data-doc_size = ( tab_lines - 1 ) * 255 + strlen(
wa_content_txt ).
* Creation of the entry for the compressed document
* Ab welcher Zeile der Text im Mailbody dargestellt werden soll.
clear wa_packlist-transf_bin.
wa_packlist-head_start = 1.
wa_packlist-head_num = 0.
wa_packlist-body_start = 1.
wa_packlist-body_num = tab_lines.
* Dokumenten Typ Mail Body/Header HTM / TXT /,
* gilt nicht für nicht angehängtes File.
wa_packlist-doc_type = 'HTM'.
append wa_packlist to it_packlist.
* wa_object_header = 'TEST.txt'. "'TEST.TXT'.
* append wa_object_header to it_object_header.
*File
* Binäre Daten in die Tabelle it_content_bin.
* ASCII / Texte in die Tabelle it_content_txt
* appenden.
do 3 times.
zahl = zahl + 1.
concatenate zahl ' ' into wa_content_bin.
* wa_content_bin = zahl .
* append wa_content_bin to it_content_bin.
append wa_content_bin to it_content_txt.
enddo.
wa_content_bin = 'Blödsinnstext'.
* append wa_content_bin to it_content_bin.
append wa_content_bin to it_content_txt.
describe table it_content_txt lines end.
tab_lines = tab_lines + 1. "Anzahl der Mailbody Zeilen.
* Ohne X Übertrag im ASCII Format, mit X Übertrag im Binär Format.
* Im binär Format Zeilenumbruch mit <CRLF> (hex = 0D0A).
wa_packlist-transf_bin = ' '.
* Ab welcher Zeile das Textfile anfängt.
wa_packlist-head_start = tab_lines.
wa_packlist-head_num = tab_lines.
wa_packlist-body_start = tab_lines.
* In welcher Zeile das Textfile endet.
wa_packlist-body_num = end.
* RAW überträgt im Originalformat,
* andere Möglichekeiten 'TXT' 'RTF' 'DOC' 'XLS'
wa_packlist-doc_type = 'RAW'.
* wa_packlist-obj_name = 'TEST2.txt'.
* Name der angehängten Datei, das Dateisuffix wird über den Type
* automatisch angehängt.
wa_packlist-obj_descr = 'Filename'.
* Größe des angehängten Files.
wa_packlist-doc_size = tab_lines * 255.
append wa_packlist to it_packlist.
endform.
Ich hoffe das ist verständlich.
Thomas aus Minden