cancel
Showing results for 
Search instead for 
Did you mean: 

Problem by Sending an Email with attached Adobe Interactive Form (Code)

Former Member
0 Kudos

Thanks. I have written Programm, but it does not work as i want it to do. I will send an Email with attached Adobe Interactive Firm to KevinGrimm9@gmx.de. I tried it with "*lo_recipient = cl_sapuser_bcs=>create( sy-uname )" at the marked(bold, fat) position. It worked but the Email was send to my SAP-Account, but i want to send to KevinGRimm9@gmx.de, so I tried this (see at code in bold, fat):

lo_rec TYPE adr6-smtp_addr VALUE 'KevinGrimm9@gmx.de'. " Empfänger Receiver

lo_recipient = cl_cam_address_bcs=>create_internet_address( lo_rec ).

But it doens`t send the email.

Can anybody help me please???

Kevin

Here my Code:

*----


*

  • Report FP_EXAMPLE_01

*----


*

  • Printing of documents using PDF based forms

*----


*

REPORT z_example_02.

  • Data declaration

DATA: carr_id TYPE sbook-carrid,

customer TYPE scustom,

bookings TYPE ty_bookings,

connections TYPE ty_connections,

fm_name TYPE rs38l_fnam,

fp_docparams TYPE sfpdocparams,

fp_outputparams TYPE sfpoutputparams,

error_string TYPE string,

l_booking TYPE sbook,

t_sums TYPE TABLE OF sbook,

l_sums LIKE LINE OF t_sums,

fp_formoutput TYPE fpformoutput.

PARAMETER: p_custid TYPE scustom-id DEFAULT 38.

SELECT-OPTIONS: s_carrid FOR carr_id DEFAULT 'AA' TO 'ZZ'.

PARAMETER: p_form TYPE tdsfname DEFAULT 'FP_EXAMPLE_01'.

PARAMETER: language TYPE sfpdocparams-langu DEFAULT 'E'.

PARAMETER: country TYPE sfpdocparams-country DEFAULT 'US'.

  • Get data from the following tables: scustom(Flight customer)

  • sbook (Single flight reservation)

  • spfli (Flight plan)

SELECT SINGLE * FROM scustom INTO customer WHERE id = p_custid.

CHECK sy-subrc = 0.

SELECT * FROM sbook INTO TABLE bookings

WHERE customid = p_custid

AND carrid IN s_carrid

ORDER BY PRIMARY KEY.

SELECT * FROM spfli INTO TABLE connections

FOR ALL ENTRIES IN bookings

WHERE carrid = bookings-carrid

AND connid = bookings-connid

ORDER BY PRIMARY KEY.

  • Print data:

  • First get name of the generated function module

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

EXPORTING

i_name = p_form

IMPORTING

e_funcname = fm_name.

IF sy-subrc <> 0.

MESSAGE e001(fp_example).

ENDIF.

  • Set output parameters and open spool job

fp_outputparams-nodialog = 'X'. " suppress printer dialog popup

fp_outputparams-getpdf = 'X'. " launch print preview

CALL FUNCTION 'FP_JOB_OPEN'

CHANGING

ie_outputparams = fp_outputparams

EXCEPTIONS

cancel = 1

usage_error = 2

system_error = 3

internal_error = 4

OTHERS = 5.

  • Set form language and country (->form locale)

fp_docparams-langu = language.

fp_docparams-country = country.

*fp_docparams-fillable = 'X'.

*fp_docparams-langu = 'E'. "wird jetzt automatisch gesetzt, bzw. kann dynamisch verändert werden

*fp_docparams-country = 'GB'. "wird jetzt automatisch gesetzt, bzw. kann dynamisch verändert werden

  • currency key dependant summing

LOOP AT bookings INTO l_booking.

l_sums-forcuram = l_booking-forcuram.

l_sums-forcurkey = l_booking-forcurkey.

COLLECT l_sums INTO t_sums.

ENDLOOP.

  • Now call the generated function module

CALL FUNCTION fm_name

EXPORTING

/1bcdwb/docparams = fp_docparams

customer = customer

bookings = bookings

connections = connections

t_sums = t_sums

IMPORTING

/1bcdwb/formoutput = fp_formoutput

EXCEPTIONS

usage_error = 1

system_error = 2

internal_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'

IMPORTING

e_adserrstr = error_string.

IF NOT error_string IS INITIAL.

  • we received a detailed error description

WRITE:/ error_string.

EXIT.

ELSE.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

  • Close spool job

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.

*********************Send the form*******************

*********************to the Customer*****************

*********************via Email***********************

*IF i_down = abap_true.

  • DATA: filename TYPE string,

  • path TYPE string,

  • fullpath TYPE string,

  • default_extension TYPE string VALUE 'PDF'.

Data:

lt_att_content_hex TYPE solix_tab.

*DATA: data_tab TYPE TABLE OF x255.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = fp_formoutput-pdf

TABLES

binary_tab = lt_att_content_hex.

CLASS cl_bcs DEFINITION LOAD.

DATA:

lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.

lo_send_request = cl_bcs=>create_persistent( ).

DATA:

lt_message_body TYPE bcsy_text VALUE IS INITIAL.

DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.

APPEND 'Dear Vendor,' TO lt_message_body.

APPEND ' ' TO lt_message_body.

APPEND 'Please fill the attached form and send it back to us.'

TO lt_message_body.

APPEND ' ' TO lt_message_body.

APPEND 'Thank You,' TO lt_message_body.

lo_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = lt_message_body

i_subject = 'Vendor Payment Form' ).

DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.

TRY.

lo_document->add_attachment(

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = 'Vendor Payment Form'

i_att_content_hex = lt_att_content_hex ).

CATCH cx_document_bcs INTO lx_document_bcs.

ENDTRY.

lo_send_request->set_document( lo_document ).

DATA:

lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
lo_send TYPE adr6-smtp_addr VALUE 'altehuette@gmx.de'. "Absender SENDER
lo_sender = cl_cam_address_bcs=>create_internet_address( lo_send ).

  • Set sender

lo_send_request->set_sender(

EXPORTING

i_sender = lo_sender ).

  • Create recipient

DATA:

lo_recipient type ref to if_recipient_bcs value is initial.

Data:

lo_rec TYPE adr6-smtp_addr VALUE 'KevinGrimm9@gmx.de'. " Empfänger Receiver

lo_recipient = cl_cam_address_bcs=>create_internet_address( lo_rec ).

*lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

    • Set recipient

lo_send_request->add_recipient(

EXPORTING

i_recipient = lo_recipient

i_express = 'X' ).

*lo_send_request->add_recipient(

*EXPORTING

*i_recipient = lo_recipient

*i_express = 'X' ).

  • Send email

DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.

lo_send_request->send(

EXPORTING

i_with_error_screen = 'X'

RECEIVING

result = lv_sent_to_all ).

COMMIT WORK.

MESSAGE 'The payment form has been emailed to the Vendor' TYPE 'I'.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Kevin,

Please try this code to send your mail, i wrote it and works well in many system.

Take care if in your profile you got an e-mail adress define .

Take care also of trnasaction SCOT customizing, are you able to send mail to e-mail adress ?

Let me know if it's works.

Best regards.

<i>**----


**

    • CLASS-DEFINITIONS

**

**----


**

DATA: send_request TYPE REF TO cl_bcs.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

*

**----


**

    • INTERNAL TABLES

**

**----


**

DATA: l_mailtext TYPE soli_tab.

DATA: iaddsmtp TYPE TABLE OF bapiadsmtp.

DATA: ireturn TYPE TABLE OF bapiret2.

*

**----


**

    • VARIABLES

**

**----


**

DATA: mail_line LIKE LINE OF l_mailtext.

DATA: bapiadsmtp TYPE bapiadsmtp.

DATA: subject TYPE so_obj_des.

DATA : att_subject TYPE so_obj_des.

*

DATA : w_except TYPE REF TO cx_root .

CONSTANTS : c_defmail TYPE ad_smtpadr VALUE

'bdessertenne@aegis-consulting.fr' .

FIELD-SYMBOLS : <smtp> TYPE bapiadsmtp.

*Convert the pdf given by function module into Binary .

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = output-pdf "PDF file from function module

TABLES

binary_tab = hexa.

*Set subject of the mail

subject = 'Exemple de PDF interactif'.

  • Set text of the mail

mail_line = 'Merci de remplir le formulaire et nous le retourner'.

APPEND mail_line TO l_mailtext .

  • Set the name of the attached document

att_subject = 'Template du PDF'.

TRY.

  • Create persistent send request

send_request = cl_bcs=>create_persistent( ).

  • Get sender object

sender = cl_sapuser_bcs=>create( sy-uname ).

  • Add sender

CALL METHOD send_request->set_sender

EXPORTING

i_sender = sender.

  • Read the E-Mail address for the user

CALL FUNCTION 'BAPI_USER_GET_DETAIL'

EXPORTING

username = sy-uname

TABLES

return = ireturn

addsmtp = iaddsmtp.

LOOP AT iaddsmtp ASSIGNING <smtp> WHERE std_no = 'X'.

CLEAR bapiadsmtp.

MOVE <smtp> TO bapiadsmtp.

ENDLOOP.

CASE bapiadsmtp-e_mail.

WHEN space.

  • No adress main for user, so send it to the default mail adress

recipient =

cl_cam_address_bcs=>create_internet_address( c_defmail ).

WHEN OTHERS.

recipient =

cl_cam_address_bcs=>create_internet_address( bapiadsmtp-e_mail ).

ENDCASE.

  • Add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'

i_copy = space

i_blind_copy = space

i_no_forward = space.

  • Set that you don't need a Return Status E-mail

CALL METHOD send_request->set_status_attributes

EXPORTING

i_requested_status = 'E'

i_status_mail = 'E'.

  • set send immediately flag

send_request->set_send_immediately( 'X' ).

*Build Document

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = l_mailtext

i_subject = subject ).

  • add attachment to document

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = att_subject

i_att_content_hex = hexa.

  • Add document to send request

CALL METHOD send_request->set_document( document ).

  • Send document

CALL METHOD send_request->send( ).

COMMIT WORK.

CATCH cx_send_req_bcs INTO w_except.

CATCH cx_address_bcs INTO w_except.

CATCH cx_document_bcs INTO w_except.

ENDTRY.</i>

Former Member
0 Kudos

Thanks, but i don`t find the problem: I tried with sender: KEvinGrimm9@gmx.de and Receiver: Sy-uname. And it works. But if i try to send from one Internet Email to another, it doesen`t work. Or from SAP-User to Internet-Email-Account: it also doesn`t work.

Where could i see in SCOT if I can send and Receive???

This is the Code:

DATA:

lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL.

*lo_send TYPE adr6-smtp_addr VALUE 'KevinGrimm9@gmx.de'.

*lo_sender = cl_cam_address_bcs=>create_internet_address( lo_send ).

lo_sender = cl_cam_address_bcs=>create_internet_address( 'altehuette@gmx.de' ).

  • Set sender

lo_send_request->set_sender(

EXPORTING

i_sender = lo_sender ).

  • Create recipient

*CONSTANTS : c_defmail TYPE ad_smtpadr VALUE 'altehuette@gmx.de' .

DATA:

lo_recipient type ref to if_recipient_bcs. " value is initial.

*lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

*lo_recipient type ref to if_recipient_bcs.

lo_recipient = cl_cam_address_bcs=>create_internet_address( 'KevinGrimm9@gmx.de' ).

Former Member
0 Kudos

Hi,

In scot transaction , go to <i>Option->Default Domain</i> , here you will define the default domain for e-mail adress that mean if your user don't have an e-mail adress, the system will generate one's with username@defaultdomain.

Know, check in scot the SMTP node by double-cliking on it, a popup will appear . On top of the popup you got <i>general information</i> block there check if <i>node in use</i> is set to true screen you . On the same screen you got SMTP Connection, check there if the SMTP definition correspond to your SMTP server ....

Fore more explanation about Scot customizing check this link

<a href="/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface Mail from SAP system</a>.

Hope it's help you

Former Member
0 Kudos

Hi Kevin,

Do you solved it ?

Former Member
0 Kudos

No, on Monday there comes a person who can help me....I hope so. I don`t know the mailhost, mailport and Codepage. I don`t know where to get these Informations. I hope on monday the person gives me the right stuff...

or can you tell me where i can get these Informations???

Former Member
0 Kudos

Hi Kevin ,

For the mail server you can have a look at your e-mail account you should find your SMTP server .

For the port, usually it's 25 .

For codepage, set the value to "No conversion" most of the case that's works .

Try and tell me .