Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3022

Re: How to Send attachments with mail that created using cl_gos_document_service->create_attachment method

$
0
0

HI,

 

     I am  done this based on your help Thanks For this, this mail is send with attachment that I have already created using >create_attachment method' , this attachment successfully sent and open in SOST Display document BUT When I am  received mail with attachment on external mail system i.e Gmail or Outlook that attached file will not opened getting error message (There was an error opening this document. The file is damaged and could not be repaired)

 

Attached image SOST: Display doc. IMG.

 

Following Program I used to do this. Please look into this for solution

 

Program:

 

DATA : t_hextab TYPE TABLE OF string,
l_file
TYPE string,
t_mailhex
TYPE solix_tab,
gr_recipient    
TYPE REF TO if_recipient_bcs,
it_contents
TYPE soli_tab,
wa_contents
LIKE LINE OF it_contents,
lv_filename
TYPE string.
DATA : oref   TYPE REF TO cx_root,
gr_bcs_exception
TYPE REF TO cx_bcs.
DATA :gv_email         TYPE adr6-smtp_addr,
t_body   
TYPE TABLE OF solisti1,
lv_attach_name
TYPE sood-objdes,
l_subject
TYPE so_obj_des,
l_document
TYPE REF TO cl_document_bcs,
w_document
TYPE REF TO cl_bcs,
l_result
TYPE os_boolean.
DATA mailid01 TYPE string.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: send_request       TYPE REF TO cl_bcs.
DATA subject TYPE char50.
RANGES: matnr_temp FOR mara-matnr,
werks_temp
FOR t001w-werks.
gv_email
= 'amsk@abc.com'.
DATA l_folder_id TYPE soodk.
DATA l_object_id TYPE soodk.
DATA document_id TYPE sofmk.

* Set folder
l_folder_id
-objtp = 'FOL'."document_id-foltp.
l_folder_id
-objyr = '29'."document_id-folyr.
l_folder_id
-objno = '000000000015'."document_id-folno.
* Set Object
l_object_id
-objtp = 'EXT'."document_id-doctp.
l_object_id
-objyr = '40'."document_id-docyr.
l_object_id
-objno = '000000001848'."document_id-docno.

* Read the document content
DATA document_content  TYPE STANDARD TABLE OF soli.
CALL FUNCTION 'SO_OBJECT_READ'
EXPORTING
folder_id                 
= l_folder_id
object_id                 
= l_object_id
TABLES
objcont                   
= document_content
EXCEPTIONS
active_user_not_exist     
= 1
communication_failure     
= 2
component_not_available   
= 3
folder_not_exist          
= 4
folder_no_authorization   
= 5
object_not_exist          
= 6
object_no_authorization   
= 7
operation_no_authorization
= 8
owner_not_exist           
= 9
parameter_error           
= 10
substitute_not_active     
= 11
substitute_not_defined    
= 12
system_failure            
= 13
x_error                   
= 14
OTHERS                     = 15.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DATA : it_soli_tab TYPE soli_tab,
it_solix_tab 
TYPE solix_tab.
CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB' "
EXPORTING
ip_solitab
=   document_content"soli_tab
IMPORTING
ep_solixtab
=    it_solix_tab.

TRY.
* * CREATE THE DOCUMENT WITH CONTENTS
CLEAR l_subject.
l_subject
= subject.
CREATE OBJECT l_document.
l_document
= cl_document_bcs=>create_document(
i_type      
= 'HTM'
i_subject   
= l_subject
i_length    
= '1000'
i_language  
= sy-langu
i_importance
= '1'
i_text      
= document_content"it_contents
i_hex    
= it_solix_tab
).

CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type   
= 'pdf'
i_attachment_subject
= 'lv_attach_name'
i_att_content_hex   
= it_solix_tab."t_mailhex.
w_document
= cl_bcs=>create_persistent( ).
CALL METHOD w_document->set_document( l_document ).
gr_recipient
= cl_cam_address_bcs=>create_internet_address( gv_email ).
"Add recipient to send request
CALL METHOD w_document->add_recipient
EXPORTING
i_recipient
= gr_recipient
i_express  
= 'U'.
*     * SEND THE MAIL
CALL METHOD w_document->send(
EXPORTING
i_with_error_screen
= 'X'
RECEIVING
result             
= l_result ).
*     * YOU CAN VERIFY THE STATUS IN THE LIST, YOU CAN ALSO SUBMIT THIS AS A BACKGROUND JOB.
IF l_result = 'X'.
MESSAGE 'Mail sent successfully' TYPE 'S'.
COMMIT WORK.
ELSE.
MESSAGE 'Error in sending Mail' TYPE 'S' DISPLAY LIKE 'E'.
ROLLBACK WORK.
ENDIF.
CLEAR l_result.
CATCH cx_bcs INTO gr_bcs_exception.
WRITE:
'Error!',
'Error type:',
gr_bcs_exception
->error_type.
MESSAGE 'Error in sending Mail' TYPE 'S' DISPLAY LIKE 'E'.
ENDTRY
.


Thanks

Ams K.


Viewing all articles
Browse latest Browse all 3022

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>