Skip to Content

Zip file attached in mail is not recognized by gmail

Hi all,

I need generate a txt file, compress it into a zip file and send e-mail attachment, but gmail does not recognize the file extension, and if I download the zip file from hotmail, the txt file is not formatted in columns.

This is the correct column format

This is the incorrect column format

This is file in gmail and downloaded

This is program

CALL FUNCTION 'LIST_TO_ASCI'
     TABLES
       listasci           = ascilist
       listobject         = listtab
     EXCEPTIONS
       empty_list         = 1
       list_index_invalid = 2
       OTHERS             = 3.

data lc_newline  type c value cl_abap_char_utilities=>cr_lf.

   clear lv_strmsg.
   loop at ascilist. " into wa_text.
       concatenate lv_strmsg ascilist-line lc_newline into lv_strmsg.
   endloop.

clear: lv_xstrmsg, lv_encoding. lv_encoding = '4130'. " I try with 1160, 4110, 4120, also without this parameter CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING TEXT = lv_strmsg ENCODING = lv_encoding IMPORTING BUFFER = lv_xstrmsg.
TRY. send_request = cl_bcs=>create_persistent( ). lv_subject = 'subject'. lv_name_str = 'name_file.txt'. create object zipper. zipper->add( name = lv_name_str content = lv_xstrmsg ). lv_zipfilehex = zipper->save( ). refresh binary_content. CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING BUFFER = lv_zipfilehex IMPORTING OUTPUT_LENGTH = lv_size TABLES BINARY_TAB = binary_content. PERFORM body_mail CHANGING main_text . document = cl_document_bcs=>create_document( i_type = 'HTM' i_text = main_text i_subject = lv_subject ). size = lv_size. document->add_attachment( i_attachment_type = 'zip' i_attachment_subject = lv_name i_attachment_size = size i_att_content_hex = binary_content ). send_request->set_document( document ). email = 'mail@gmail.com'. recipient = cl_cam_address_bcs=>create_internet_address( email ). send_request->add_recipient( recipient ). CALL METHOD send_request->set_status_attributes EXPORTING i_requested_status = 'E'. sent_to_all = send_request->send( i_with_error_screen = 'X' ). COMMIT WORK. IF sent_to_all IS INITIAL.A
size = lv_size. document->add_attachment( i_attachment_type = 'zip' i_attachment_subject = lv_name i_attachment_size = size i_att_content_hex = binary_content ). send_request->set_document( document ). email = 'mail@gmail.com'. recipient = cl_cam_address_bcs=>create_internet_address( email ). send_request->add_recipient( recipient ). CALL METHOD send_request->set_status_attributes EXPORTING i_requested_status = 'E'. sent_to_all = send_request->send( i_with_error_screen = 'X' ). COMMIT WORK. GE s022(so). CALL METHOD send_request->set_status_attributes EXPORTING i_requested_status = 'E'. sent_to_all = send_request->sen d( i_ sent_to_all = send_request->send( i_with_error_screen = 'X' ). COMMIT WORK. with_error_screen = 'X' ). COMMIT WORK.

Best regards,

Robert

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jul 15, 2016 at 11:05 PM

    Sorry,

    The code is not copied properly:

    CALL FUNCTION 'LIST_TO_ASCI'

    TABLES

    listasci = ascilist

    listobject = listtab

    EXCEPTIONS

    empty_list = 1

    list_index_invalid = 2

    OTHERS = 3.

    clear lv_strmsg.

    loop at ascilist.

    concatenate lv_strmsg ascilist-line

    into lv_strmsg separated by CL_ABAP_CHAR_UTILITIES=>NEWLINE.

    endloop.


    clear: lv_xstrmsg, lv_encoding.

    lv_encoding = '4130'. " I try with 1160, 4110, 4120, also without this parameter

    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

    EXPORTING

    TEXT = lv_strmsg

    ENCODING = lv_encoding

    IMPORTING

    BUFFER = lv_xstrmsg.


    TRY.

    send_request = cl_bcs=>create_persistent( ).

    lv_subject = 'subject'.

    lv_name_str = 'name_file.txt'.

    create object zipper.

    zipper->add( name = lv_name_str

    content = lv_xstrmsg ).

    lv_zipfilehex = zipper->save( ).

    refresh binary_content.

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

    BUFFER = lv_zipfilehex

    IMPORTING

    OUTPUT_LENGTH = lv_size

    TABLES

    BINARY_TAB = binary_content.

    PERFORM body_mail CHANGING main_text .

    document = cl_document_bcs=>create_document(

    i_type = 'HTM'

    i_text = main_text

    i_subject = lv_subject ).

    size = lv_size.

    document->add_attachment(

    i_attachment_type = 'zip'

    i_attachment_subject = lv_name

    i_attachment_size = size

    i_att_content_hex = binary_content ).

    send_request->set_document( document ).

    email = 'mail@gmail.com'.

    recipient = cl_cam_address_bcs=>create_internet_address( email ).

    send_request->add_recipient( recipient ).

    CALL METHOD send_request->set_status_attributes

    EXPORTING

    i_requested_status = 'E'.

    sent_to_all = send_request->send( i_with_error_screen = 'X' ).

    COMMIT WORK.

    IF sent_to_all IS INITIAL.

    MESSAGE i500(sbcoms) WITH email.

    ELSE.

    MESSAGE s022(so).

    ENDIF.

    CATCH cx_bcs INTO bcs_exception.

    MESSAGE i865(so) WITH bcs_exception->error_type.

    ENDTRY.

    Best regards,

    Robert

    Add a comment
    10|10000 characters needed characters exceeded

    • If it was okay without zip, but KO when you zip, as there's no change in the zipped document (if you unzip it, it will look exactly the same), so I think the error is only because of the software you use to read the zipped document.

      Did you open the TXT file directly from the zip viewer software, or did you unzip it and view it with the same software as initially? (at the time your program didn't zip).

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.