on 08-14-2007 4:00 PM
Hi there,
i want to send an email with a pdf-document attachment out of the sap system (NetWeaver) with the integrated smtp-plugin.
My ABAP Program works fine, without error messages. The Problem the E-Mail doesn't arrive the email recipient.
And in the Transaction SOST i cant see an send request...
Here my abap code:
parameter sem_adr type ADR6-SMTP_ADDR default 'xxx@freenet.de'.
Data fm_name type funcname.
try.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
I_NAME = 'fp_test_00'
IMPORTING
*In fm_name ist der Funktionsmodulname gespeichert
E_FUNCNAME = fm_name
EXCEPTIONS
others = 0.
catch cx_fp_api_repository. "#EC NO_HANDLER
catch cx_fp_api_usage. "#EC NO_HANDLER
catch cx_fp_api_internal. "#EC NO_HANDLER
endtry.
Data: l_outputparams type sfpoutputparams.
*Start Formular Prozess
*-GETPDF = X bedeutet, dass wir ein pdf zurück bekommen.
l_outputparams-getpdf = 'X'.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
IE_OUTPUTPARAMS = l_outputparams
EXCEPTIONS
CANCEL = 1
USAGE_ERROR = 2
SYSTEM_ERROR = 3
INTERNAL_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATA: fp_docparams type sfpdocparams,
fp_result type fpformoutput.
*Einstellung von Formularparametern
*Durch X wird festgelegt, dass das generierte Formular ein
*interaktives Formular ist.
fp_docparams-fillable = 'X'.
*Festlegen der Sprache
fp_docparams-langu = sy-langu.
*Funktionsmodul mit dem Namen /1BCDWB/SM00000007 wird aufgerufen
data text type TSFTEXT.
CALL FUNCTION '/1BCDWB/SM00000007'
EXPORTING
/1BCDWB/DOCPARAMS = fp_docparams
TEXTLINES = text
IMPORTING
/1BCDWB/FORMOUTPUT = fp_result
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4 .
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Data: pdf type fpformoutput-pdf.
pdf = fp_result-pdf.
*Ende Formular Prozesses einleiten
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Eine E-Mail erstellen und versenden
Da die Klasse Exceptions schmeisst muss es in einen Try
*Block genommen werden
Data bcs_exception type ref to cx_bcs.
try.
Text an den E-Mail Body hängen
data: l_subject type so_obj_des,
l_mailtext type bcsy_Text,
l_mailtext_row type soli.
l_subject = 'TEST Interactive Form'.
concatenate 'Bitte ausgefüllt an:'
'xxx.xxx@xxx.de'
into l_mailtext_row.
append l_mailtext_row to l_mailtext.
E-Mail Dokument erstellen
Data: Document type ref to cl_document_bcs,
num_rows type i,
textlength type so_obj_len.
describe table l_mailtext lines num_rows.
num_rows = num_rows * 255.
move num_rows to textlength.
*RAW steht für Standardtext
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_mailtext
i_length = textlength
i_subject = l_subject ).
*Anhang anhängen
Data: attdoctype type soodk-objtp value 'PDF',
atttitle type sood-objdes,
attsize type sood-objlen,
pdftab type solix_tab.
atttitle ='CreateFlight'.
attsize = xstrlen( pdf ).
pdftab = cl_document_bcs=>xstring_to_solix(
ip_xstring = pdf ).
document->add_attachment( exporting i_attachment_type = attdoctype
i_attachment_subject = atttitle
i_attachment_size = attsize
i_attachment_language = sy-langu
i_att_content_hex = pdftab ).
*Eine persistente Sender Anfrage an den Mail-Server senden
Data: send_request type ref to cl_bcs.
send_request = cl_bcs=>create_persistent( ).
*Document an Sender Anfrage hängen
send_request->set_document( document ).
*Get sender object
data: sender type ref to cl_sapuser_bcs.
sender = cl_sapuser_bcs=>create( 'SAPMAIL' ).
*Add sender
Call method send_request->set_sender
exporting i_sender = sender.
*Empfänger erstellen
Data: recipient type ref to if_recipient_bcs.
recipient = cl_cam_address_bcs=>create_internet_address( sem_adr ).
*Empfänger mit seinen Attributen an die Sender Anfrage anhängen
send_request->add_recipient( exporting i_recipient = recipient ).
*Senden auf sofort setzten
send_request->set_send_immediately( 'X' ).
commit work.
write 'E-Mail wurde gesendet'.
catch cx_bcs into bcs_exception.
data: ex_msg type string.
ex_msg = bcs_exception->get_text( ).
write: 'Caught exception', ex_msg.
Regards
Markus
Message was edited by:
Markus Semrau
Hi,
have you already setup SCOT FOR EMAILS? or your jobs are running?
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.